Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodes.Module don't have a end_lineno and end_col_offset #1273

Closed
DanielNoord opened this issue Nov 22, 2021 · 1 comment · Fixed by #1262
Closed

nodes.Module don't have a end_lineno and end_col_offset #1273

DanielNoord opened this issue Nov 22, 2021 · 1 comment · Fixed by #1262
Labels
Milestone

Comments

@DanielNoord
Copy link
Collaborator

DanielNoord commented Nov 22, 2021

Steps to reproduce

import astroid

code = """
    print("a module")
    """

module = astroid.parse(code)
print(module.end_lineno)
print(module.end_col_offset)

Current behavior

AttributeError on both of the last lines.

Expected behavior

@cdce8p Let me know if I misunderstood you, but I thought we wanted these to be accessible on all nodes, just initialised as None.
If that was not the case, I would make the case to do so as it allows you to do node.end_lineno without running in to AttributeError's.

Version

Latest main.

@cdce8p
Copy link
Member

cdce8p commented Nov 22, 2021

but I thought we wanted these to be accessible on all nodes, just initialised as None.

Yeah, that was the idea initially.

AttributeError on both of the last lines.

For now a workaround would be to use hasattr(node, "end_lineno"). Not pretty but it should do. That should unblock pylint-dev/pylint#5343.

--
We could try to address it in #1262. The issue are these lines here
https://github.com/PyCQA/astroid/blob/775c8f7acb97e50cd643b6e1a20042aa8cfa98a3/astroid/nodes/scoped_nodes.py#L472-L475
combined with the missing super().__init__() call.
I noticed just now that the lineno for Module is set to 0. The type annotation thus doesn't make sense.
https://github.com/PyCQA/astroid/blob/775c8f7acb97e50cd643b6e1a20042aa8cfa98a3/astroid/nodes/scoped_nodes.py#L387-L396

There could also be an argument that it should be lineno = 1 instead. As all are 1-indexed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants