Message408561
Looks like this little patch can solve this problem:
```
def unparse(ast_obj):
unparser = _Unparser()
--- return unparser.visit(ast_obj)
+++ return unparser.visit(fix_missing_locations(ast_obj))
```
But, I am not sure we should call this helper here.
Another approach is to refactor `get_type_comment` function into something like this:
```
def get_type_comment(self, node):
comment = None
if hasattr(node, 'lineno'):
comment = self._type_ignores.get(node.lineno)
comment = comment or node.type_comment
if comment is not None:
return f" # type: {comment}"
```
I feel like this is more suitable for this case. Even `ast.pyi` has this line:
```
# TODO: Not all nodes have all of the following attributes
lineno: int
col_offset: int
```
So, I am going to propose a PR with the second option. Please, send your feedback! |
|
Date |
User |
Action |
Args |
2021-12-14 20:57:42 | sobolevn | set | recipients:
+ sobolevn, TheRobotCarlson |
2021-12-14 20:57:42 | sobolevn | set | messageid: <1639515462.32.0.257931488159.issue46073@roundup.psfhosted.org> |
2021-12-14 20:57:42 | sobolevn | link | issue46073 messages |
2021-12-14 20:57:42 | sobolevn | create | |
|