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.21:32:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639517572.45.0.0212068624511.issue46073@roundup.psfhosted.org>
In-reply-to
Content
Or, maybe this is a correct thing to do. Consider this case. Let's say we now check that `node` has `lineno` and exclude ones that don't.

Then, we write this test (in `Lib/test/test_unparse`):

```
    def test_unparse_nodes_without_lineno(self):
        # https://bugs.python.org/issue46073
        def create_module(ignores):
            return ast.Module(
                body=[
                    ast.FunctionDef(
                        name="items_needed",
                        args=ast.arguments(
                            posonlyargs=[], args=[],
                            kwonlyargs=[], kw_defaults=[], defaults=[],
                        ),
                        body=[ast.Pass()], decorator_list=[],
                    ),
                ],
                type_ignores=ignores,
            )

        ast1 = create_module([])
        self.assertASTEqual(ast1, ast.parse(ast.unparse(ast1)))

        ast2 = create_module([ast.TypeIgnore(lineno=1, tag='')])
        # This fill fail without `ast2 = ast.fix_missing_locations(ast2)`
        self.assertASTEqual(ast2, ast.parse(ast.unparse(ast2), type_comments=True))
```

In this case the second `assert` will fail, because the resulting codes would be different:

```
# "original"
def items_needed():  # type: ignore
    pass

# unparsed
def items_needed():
    pass
```

So, basically users will get different code. Which is not a good thing.

So, maybe raising an error that some `node` does not have `lineno` is good after all?
History
Date User Action Args
2021-12-14 21:32:52sobolevnsetrecipients: + sobolevn, TheRobotCarlson
2021-12-14 21:32:52sobolevnsetmessageid: <1639517572.45.0.0212068624511.issue46073@roundup.psfhosted.org>
2021-12-14 21:32:52sobolevnlinkissue46073 messages
2021-12-14 21:32:52sobolevncreate