[issue46073] ast.unparse produces: 'FunctionDef' object has no attribute 'lineno' for valid module

Brian Carlson report at bugs.python.org
Tue Dec 14 16:14:03 EST 2021


Brian Carlson <briancarlson6174 at gmail.com> added the comment:

The second solution seems more optimal, in my opinion. I monkey patched the function like this in my own code:
```
def get_type_comment(self, node):
    comment = self._type_ignores.get(node.lineno) if hasattr(node, "lineno") else node.type_comment
    if comment is not None:
        return f" # type: {comment}"
```

Thanks!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46073>
_______________________________________


More information about the Python-bugs-list mailing list