This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sobolevn
Recipients TheRobotCarlson, sobolevn
Date 2021-12-14.20:57:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639515462.32.0.257931488159.issue46073@roundup.psfhosted.org>
In-reply-to
Content
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!
History
Date User Action Args
2021-12-14 20:57:42sobolevnsetrecipients: + sobolevn, TheRobotCarlson
2021-12-14 20:57:42sobolevnsetmessageid: <1639515462.32.0.257931488159.issue46073@roundup.psfhosted.org>
2021-12-14 20:57:42sobolevnlinkissue46073 messages
2021-12-14 20:57:42sobolevncreate