Skip to content

Commit dddf2da

Browse files
DanielNoordcdce8p
andauthored
Make Module call the __init__ of NodeNG (#1262)
Co-authored-by: Marc Mueller <[email protected]>
1 parent e3730a7 commit dddf2da

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Release date: TBA
2424

2525
Closes #1260
2626

27+
* Fix ``Module`` nodes not having a ``col_offset``, ``end_lineno``, and ``end_col_offset``
28+
attributes.
29+
2730
* Fix typing and update explanation for ``Arguments.args`` being ``None``.
2831

2932
* Fix crash if a variable named ``type`` is subscripted in a generator expression.

astroid/nodes/scoped_nodes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,8 @@ class Module(LocalsDictNodeNG):
389389
390390
:type: int or None
391391
"""
392-
lineno = 0
392+
lineno: Literal[0] = 0
393393
"""The line that this node appears on in the source code.
394-
395-
:type: int or None
396394
"""
397395

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

472-
lineno: None
473470
col_offset: None
474471
end_lineno: None
475472
end_col_offset: None
@@ -512,7 +509,6 @@ def __init__(
512509
self.file = file
513510
self.path = path
514511
self.package = package
515-
self.parent = parent
516512
self.pure_python = pure_python
517513
self.locals = self.globals = {}
518514
"""A map of the name of a local variable to the node defining the local.
@@ -526,6 +522,8 @@ def __init__(
526522
"""
527523
self.future_imports = set()
528524

525+
super().__init__(lineno=0, parent=parent)
526+
529527
# pylint: enable=redefined-builtin
530528

531529
def postinit(self, body=None):

tests/unittest_nodes_lineno.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import astroid
56
from astroid import builder, nodes
67
from astroid.const import PY38_PLUS, PY39_PLUS, PY310_PLUS
78

@@ -1221,3 +1222,14 @@ class X(Parent, var=42):
12211222
assert (c1.body[0].lineno, c1.body[0].col_offset) == (4, 4)
12221223
assert (c1.body[0].end_lineno, c1.body[0].end_col_offset) == (4, 8)
12231224
# fmt: on
1225+
1226+
@staticmethod
1227+
def test_end_lineno_module() -> None:
1228+
"""Tests for Module"""
1229+
code = """print()"""
1230+
module = astroid.parse(code)
1231+
assert isinstance(module, nodes.Module)
1232+
assert module.lineno == 0
1233+
assert module.col_offset is None
1234+
assert module.end_lineno is None
1235+
assert module.end_col_offset is None

0 commit comments

Comments
 (0)