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

2021-12-14 Thread Brian Carlson
New submission from Brian Carlson : Test file linked. When unparsing the output from ast.parse on a simple class, unparse throws an error: 'FunctionDef' object has no attribute 'lineno' for a valid class and valid AST. It fails when programmatically building the module AS

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

2021-12-14 Thread Brian Carlson
Brian Carlson 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_comm

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

2021-12-14 Thread Brian Carlson
Brian Carlson added the comment: I don't think passing `lineno` and `column` is preferred. It makes code generation harder because `lineno` and `column` are hard to know ahead of when code is being unparsed. -- ___ Python tracker &