You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-05-18.18:17:15.150>created_at=<Date2020-05-17.17:35:18.755>labels= ['type-bug', 'library', '3.9']
title="ast.get_source_segment behaviour with missing location info doesn't match docstring"updated_at=<Date2020-05-18.18:17:15.150>user='https://github.com/iritkatriel'
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.
iritkatriel
changed the title
ast.get_source_segment behaviour with missing location info doesn't match doctoring
ast.get_source_segment behaviour with missing location info doesn't match docstring
May 17, 2020
iritkatriel
changed the title
ast.get_source_segment behaviour with missing location info doesn't match doctoring
ast.get_source_segment behaviour with missing location info doesn't match docstring
May 17, 2020
New changeset e6578a2 by Irit Katriel in branch 'master': bpo-40662: Fixed ast.get_source_segment for ast nodes that have incomplete location information (GH-20157) e6578a2
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: