Nikita Sobolev <[email protected]> added the comment:
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!
----------
nosy: +sobolevn
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46073>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com