File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ Release date: TBA
24
24
25
25
Closes #1260
26
26
27
+ * Fix ``Module`` nodes not having a ``col_offset``, ``end_lineno``, and ``end_col_offset``
28
+ attributes.
29
+
27
30
* Fix typing and update explanation for ``Arguments.args`` being ``None``.
28
31
29
32
* Fix crash if a variable named ``type`` is subscripted in a generator expression.
Original file line number Diff line number Diff line change @@ -389,10 +389,8 @@ class Module(LocalsDictNodeNG):
389
389
390
390
:type: int or None
391
391
"""
392
- lineno = 0
392
+ lineno : Literal [ 0 ] = 0
393
393
"""The line that this node appears on in the source code.
394
-
395
- :type: int or None
396
394
"""
397
395
398
396
# attributes below are set by the builder module or by raw factories
@@ -469,7 +467,6 @@ class Module(LocalsDictNodeNG):
469
467
)
470
468
_other_other_fields = ("locals" , "globals" )
471
469
472
- lineno : None
473
470
col_offset : None
474
471
end_lineno : None
475
472
end_col_offset : None
@@ -512,7 +509,6 @@ def __init__(
512
509
self .file = file
513
510
self .path = path
514
511
self .package = package
515
- self .parent = parent
516
512
self .pure_python = pure_python
517
513
self .locals = self .globals = {}
518
514
"""A map of the name of a local variable to the node defining the local.
@@ -526,6 +522,8 @@ def __init__(
526
522
"""
527
523
self .future_imports = set ()
528
524
525
+ super ().__init__ (lineno = 0 , parent = parent )
526
+
529
527
# pylint: enable=redefined-builtin
530
528
531
529
def postinit (self , body = None ):
Original file line number Diff line number Diff line change 2
2
3
3
import pytest
4
4
5
+ import astroid
5
6
from astroid import builder , nodes
6
7
from astroid .const import PY38_PLUS , PY39_PLUS , PY310_PLUS
7
8
@@ -1221,3 +1222,14 @@ class X(Parent, var=42):
1221
1222
assert (c1 .body [0 ].lineno , c1 .body [0 ].col_offset ) == (4 , 4 )
1222
1223
assert (c1 .body [0 ].end_lineno , c1 .body [0 ].end_col_offset ) == (4 , 8 )
1223
1224
# 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
You can’t perform that action at this time.
0 commit comments