Author iritkatriel
Recipients benjamin.peterson, brett.cannon, iritkatriel, pablogsal, yselivanov
Date 2020-05-17.17:35:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589736918.78.0.989051663687.issue40662@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-05-17 17:35:18iritkatrielsetrecipients: + iritkatriel, brett.cannon, benjamin.peterson, yselivanov, pablogsal
2020-05-17 17:35:18iritkatrielsetmessageid: <1589736918.78.0.989051663687.issue40662@roundup.psfhosted.org>
2020-05-17 17:35:18iritkatriellinkissue40662 messages
2020-05-17 17:35:18iritkatrielcreate