summaryrefslogtreecommitdiff
path: root/astroid/rebuilder.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-03-09 15:50:22 +0100
committerGitHub <noreply@github.com>2022-03-09 15:50:22 +0100
commitc21b18ca606ded3d3016580869d9ac598086caea (patch)
tree1a72a72a9c55c99008671e2af2c63580afcdc545 /astroid/rebuilder.py
parentb0c0c450dc21bc9d901f811ce1b4e39e13a387b5 (diff)
downloadastroid-git-c21b18ca606ded3d3016580869d9ac598086caea.tar.gz
No longer pass doc to various node constructors (#1451)
Diffstat (limited to 'astroid/rebuilder.py')
-rw-r--r--astroid/rebuilder.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index 3a2350cc..7d8441e9 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -116,10 +116,8 @@ class TreeRebuilder:
self._parser_module = parser_module
self._module = self._parser_module.module
- def _get_doc(
- self, node: T_Doc
- ) -> Tuple[T_Doc, Optional["ast.Constant | ast.Str"], Optional[str]]:
- """Return the doc ast node and the actual docstring."""
+ def _get_doc(self, node: T_Doc) -> Tuple[T_Doc, Optional["ast.Constant | ast.Str"]]:
+ """Return the doc ast node."""
try:
if node.body and isinstance(node.body[0], self._module.Expr):
first_value = node.body[0].value
@@ -129,16 +127,15 @@ class TreeRebuilder:
and isinstance(first_value.value, str)
):
doc_ast_node = first_value
- doc = first_value.value if PY38_PLUS else first_value.s
node.body = node.body[1:]
# The ast parser of python < 3.8 sets col_offset of multi-line strings to -1
# as it is unable to determine the value correctly. We reset this to None.
if doc_ast_node.col_offset == -1:
doc_ast_node.col_offset = None
- return node, doc_ast_node, doc
+ return node, doc_ast_node
except IndexError:
pass # ast built from scratch
- return node, None, None
+ return node, None
def _get_context(
self,
@@ -298,10 +295,9 @@ class TreeRebuilder:
Note: Method not called by 'visit'
"""
- node, doc_ast_node, doc = self._get_doc(node)
+ node, doc_ast_node = self._get_doc(node)
newnode = nodes.Module(
name=modname,
- doc=doc,
file=modpath,
path=[modpath],
package=package,
@@ -1296,10 +1292,9 @@ class TreeRebuilder:
self, node: "ast.ClassDef", parent: NodeNG, newstyle: bool = True
) -> nodes.ClassDef:
"""visit a ClassDef node to become astroid"""
- node, doc_ast_node, doc = self._get_doc(node)
+ node, doc_ast_node = self._get_doc(node)
newnode = nodes.ClassDef(
name=node.name,
- doc=doc,
lineno=node.lineno,
col_offset=node.col_offset,
# end_lineno and end_col_offset added in 3.8
@@ -1604,7 +1599,7 @@ class TreeRebuilder:
) -> T_Function:
"""visit an FunctionDef node to become astroid"""
self._global_names.append({})
- node, doc_ast_node, doc = self._get_doc(node)
+ node, doc_ast_node = self._get_doc(node)
lineno = node.lineno
if PY38_PLUS and node.decorator_list:
@@ -1619,7 +1614,6 @@ class TreeRebuilder:
newnode = cls(
name=node.name,
- doc=doc,
lineno=lineno,
col_offset=node.col_offset,
# end_lineno and end_col_offset added in 3.8