New submission from Irit Katriel <iritkatr...@yahoo.com>:

The doctoring says "If some location information (lineno, end_lineno, 
col_offset, or end_col_offset) is missing, return None."

However:

>>> s = "12"
>>> node = ast.parse(s).body[0]
>>> ast.get_source_segment(s, node)
'12'
>>> del node.lineno
>>> ast.get_source_segment(s, node)
>>> node = ast.parse(s).body[0]
>>> del node.end_lineno
>>> ast.get_source_segment(s, node)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/iritkatriel/src/cpython/Lib/ast.py", line 336, in 
get_source_segment
    end_lineno = node.end_lineno - 1
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

In other parts of ast.py there are hasattr checks for lineno/col_offset 
alongside checks for None for end_lineno/end_col_offset. So this difference in 
behaviour of the end_ fields seems intended.

----------
components: Library (Lib)
messages: 369139
nosy: benjamin.peterson, brett.cannon, iritkatriel, pablogsal, yselivanov
priority: normal
pull_requests: 19458
severity: normal
status: open
title: ast.get_source_segment behaviour with missing location info doesn't 
match doctoring
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40662>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to