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 <>
The doctoring says "If some location information (lineno, end_lineno, col_offset, or end_col_offset) is missing, return None."


>>> s = "12"
>>> node = ast.parse(s).body[0]
>>> ast.get_source_segment(s, node)
>>> 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/", 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 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.
Date User Action Args
2020-05-17 17:35:18iritkatrielsetrecipients: + iritkatriel, brett.cannon, benjamin.peterson, yselivanov, pablogsal
2020-05-17 17:35:18iritkatrielsetmessageid: <>
2020-05-17 17:35:18iritkatriellinkissue40662 messages
2020-05-17 17:35:18iritkatrielcreate