Skip to content

Commit d594fbf

Browse files
authored
Rearrange and type attribute definition of nodes.Module (#1355)
* Rearrange and type attribute definition of ``nodes.Module``
1 parent 8532fc3 commit d594fbf

File tree

1 file changed

+38
-78
lines changed

1 file changed

+38
-78
lines changed

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 38 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import sys
5151
import typing
5252
import warnings
53-
from typing import Dict, List, Optional, TypeVar, Union, overload
53+
from typing import Dict, List, Optional, Set, TypeVar, Union, overload
5454

5555
from astroid import bases
5656
from astroid import decorators as decorators_mod
@@ -385,77 +385,30 @@ class Module(LocalsDictNodeNG):
385385

386386
_astroid_fields = ("body",)
387387

388-
fromlineno = 0
389-
"""The first line that this node appears on in the source code.
388+
fromlineno: Literal[0] = 0
389+
"""The first line that this node appears on in the source code."""
390390

391-
:type: int or None
392-
"""
393391
lineno: Literal[0] = 0
394-
"""The line that this node appears on in the source code.
395-
"""
392+
"""The line that this node appears on in the source code."""
396393

397394
# attributes below are set by the builder module or by raw factories
398395

399-
file = None
400-
"""The path to the file that this ast has been extracted from.
401-
402-
This will be ``None`` when the representation has been built from a
403-
built-in module.
404-
405-
:type: str or None
406-
"""
407-
file_bytes = None
408-
"""The string/bytes that this ast was built from.
396+
file_bytes: Union[str, bytes, None] = None
397+
"""The string/bytes that this ast was built from."""
409398

410-
:type: str or bytes or None
411-
"""
412-
file_encoding = None
399+
file_encoding: Optional[str] = None
413400
"""The encoding of the source file.
414401
415402
This is used to get unicode out of a source file.
416403
Python 2 only.
417-
418-
:type: str or None
419-
"""
420-
name = None
421-
"""The name of the module.
422-
423-
:type: str or None
424-
"""
425-
pure_python = None
426-
"""Whether the ast was built from source.
427-
428-
:type: bool or None
429-
"""
430-
package = None
431-
"""Whether the node represents a package or a module.
432-
433-
:type: bool or None
434-
"""
435-
globals = None
436-
"""A map of the name of a global variable to the node defining the global.
437-
438-
:type: dict(str, NodeNG)
439404
"""
440405

441-
# Future imports
442-
future_imports = None
443-
"""The imports from ``__future__``.
444-
445-
:type: set(str) or None
446-
"""
447406
special_attributes = ModuleModel()
448-
"""The names of special attributes that this module has.
449-
450-
:type: objectmodel.ModuleModel
451-
"""
407+
"""The names of special attributes that this module has."""
452408

453409
# names of module attributes available through the global scope
454410
scope_attrs = {"__name__", "__doc__", "__file__", "__path__", "__package__"}
455-
"""The names of module attributes available through the global scope.
456-
457-
:type: str(str)
458-
"""
411+
"""The names of module attributes available through the global scope."""
459412

460413
_other_fields = (
461414
"name",
@@ -475,53 +428,60 @@ class Module(LocalsDictNodeNG):
475428

476429
def __init__(
477430
self,
478-
name,
479-
doc,
480-
file=None,
431+
name: str,
432+
doc: str,
433+
file: Optional[str] = None,
481434
path: Optional[List[str]] = None,
482-
package=None,
483-
parent=None,
484-
pure_python=True,
485-
):
435+
package: Optional[bool] = None,
436+
parent: Literal[None] = None,
437+
pure_python: Optional[bool] = True,
438+
) -> None:
486439
"""
487440
:param name: The name of the module.
488-
:type name: str
489441
490442
:param doc: The module docstring.
491-
:type doc: str
492443
493444
:param file: The path to the file that this ast has been extracted from.
494-
:type file: str or None
495445
496446
:param path:
497-
:type path: Optional[List[str]]
498447
499448
:param package: Whether the node represents a package or a module.
500-
:type package: bool or None
501449
502450
:param parent: The parent node in the syntax tree.
503-
:type parent: NodeNG or None
504451
505452
:param pure_python: Whether the ast was built from source.
506-
:type pure_python: bool or None
507453
"""
508454
self.name = name
455+
"""The name of the module."""
456+
509457
self.doc = doc
458+
"""The module docstring."""
459+
510460
self.file = file
461+
"""The path to the file that this ast has been extracted from.
462+
463+
This will be ``None`` when the representation has been built from a
464+
built-in module.
465+
"""
466+
511467
self.path = path
468+
512469
self.package = package
470+
"""Whether the node represents a package or a module."""
471+
513472
self.pure_python = pure_python
473+
"""Whether the ast was built from source."""
474+
475+
self.globals: Dict[str, List[node_classes.NodeNG]]
476+
"""A map of the name of a global variable to the node defining the global."""
477+
514478
self.locals = self.globals = {}
515-
"""A map of the name of a local variable to the node defining the local.
516479

517-
:type: dict(str, NodeNG)
518-
"""
519-
self.body = []
520-
"""The contents of the module.
480+
self.body: Optional[List[node_classes.NodeNG]] = []
481+
"""The contents of the module."""
521482

522-
:type: list(NodeNG) or None
523-
"""
524-
self.future_imports = set()
483+
self.future_imports: Set[str] = set()
484+
"""The imports from ``__future__``."""
525485

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

0 commit comments

Comments
 (0)