Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Release date: TBA

Closes #1260

* Fix ``Module`` nodes not having a ``col_offset``, ``end_lineno``, and ``end_col_offset``
attributes.

* Fix typing and update explanation for ``Arguments.args`` being ``None``.

* Fix crash if a variable named ``type`` is subscripted in a generator expression.
Expand Down
8 changes: 3 additions & 5 deletions astroid/nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,8 @@ class Module(LocalsDictNodeNG):

:type: int or None
"""
lineno = 0
lineno: Literal[0] = 0
"""The line that this node appears on in the source code.

:type: int or None
"""

# attributes below are set by the builder module or by raw factories
Expand Down Expand Up @@ -469,7 +467,6 @@ class Module(LocalsDictNodeNG):
)
_other_other_fields = ("locals", "globals")

lineno: None
col_offset: None
end_lineno: None
end_col_offset: None
Expand Down Expand Up @@ -512,7 +509,6 @@ def __init__(
self.file = file
self.path = path
self.package = package
self.parent = parent
self.pure_python = pure_python
self.locals = self.globals = {}
"""A map of the name of a local variable to the node defining the local.
Expand All @@ -526,6 +522,8 @@ def __init__(
"""
self.future_imports = set()

super().__init__(lineno=0, parent=parent)

# pylint: enable=redefined-builtin

def postinit(self, body=None):
Expand Down
12 changes: 12 additions & 0 deletions tests/unittest_nodes_lineno.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import astroid
from astroid import builder, nodes
from astroid.const import PY38_PLUS, PY39_PLUS, PY310_PLUS

Expand Down Expand Up @@ -1221,3 +1222,14 @@ class X(Parent, var=42):
assert (c1.body[0].lineno, c1.body[0].col_offset) == (4, 4)
assert (c1.body[0].end_lineno, c1.body[0].end_col_offset) == (4, 8)
# fmt: on

@staticmethod
def test_end_lineno_module() -> None:
"""Tests for Module"""
code = """print()"""
module = astroid.parse(code)
assert isinstance(module, nodes.Module)
assert module.lineno == 0
assert module.col_offset is None
assert module.end_lineno is None
assert module.end_col_offset is None