summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-16 12:16:20 +0100
committerGitHub <noreply@github.com>2021-12-16 12:16:20 +0100
commitdddf2daaa95754772ebf8a84fb25cd689c98736e (patch)
treef6b60ea3591e3739227f75b0b1aa1e23f52e80b2
parente3730a7aaf35030edcafbb5ec0509fb8ff070e33 (diff)
downloadastroid-git-dddf2daaa95754772ebf8a84fb25cd689c98736e.tar.gz
Make Module call the __init__ of NodeNG (#1262)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
-rw-r--r--ChangeLog3
-rw-r--r--astroid/nodes/scoped_nodes.py8
-rw-r--r--tests/unittest_nodes_lineno.py12
3 files changed, 18 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 62ba3693..8ddaae2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,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.
diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py
index 0c745a4f..96a034c8 100644
--- a/astroid/nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes.py
@@ -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
@@ -469,7 +467,6 @@ class Module(LocalsDictNodeNG):
)
_other_other_fields = ("locals", "globals")
- lineno: None
col_offset: None
end_lineno: None
end_col_offset: None
@@ -512,7 +509,6 @@ class Module(LocalsDictNodeNG):
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.
@@ -526,6 +522,8 @@ class Module(LocalsDictNodeNG):
"""
self.future_imports = set()
+ super().__init__(lineno=0, parent=parent)
+
# pylint: enable=redefined-builtin
def postinit(self, body=None):
diff --git a/tests/unittest_nodes_lineno.py b/tests/unittest_nodes_lineno.py
index 75d664dc..73cf0207 100644
--- a/tests/unittest_nodes_lineno.py
+++ b/tests/unittest_nodes_lineno.py
@@ -2,6 +2,7 @@ import textwrap
import pytest
+import astroid
from astroid import builder, nodes
from astroid.const import PY38_PLUS, PY39_PLUS, PY310_PLUS
@@ -1221,3 +1222,14 @@ class TestLinenoColOffset:
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