summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-24 13:53:06 +0100
committerGitHub <noreply@github.com>2021-11-24 13:53:06 +0100
commit3a1cdb0d0daf959537a15b547dffdf9ae9dc3dc9 (patch)
tree763baf437809ffde245763856e040c446ff7b77a
parent444315963dcfec56d2539f72895ff98c07f2d31d (diff)
downloadastroid-git-3a1cdb0d0daf959537a15b547dffdf9ae9dc3dc9.tar.gz
Fix ``mypy`` warnings for ``astroid/rebuilder`` (#1244)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
-rw-r--r--astroid/nodes/node_classes.py2
-rw-r--r--astroid/rebuilder.py13
2 files changed, 11 insertions, 4 deletions
diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py
index e67e9641..52698943 100644
--- a/astroid/nodes/node_classes.py
+++ b/astroid/nodes/node_classes.py
@@ -5184,7 +5184,7 @@ class MatchSingleton(Pattern):
end_col_offset: Optional[int] = None,
parent: Optional[NodeNG] = None,
) -> None:
- self.value: Literal[True, False, None] = value
+ self.value = value
super().__init__(
lineno=lineno,
col_offset=col_offset,
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index b6430fe1..1482eece 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -107,7 +107,7 @@ class TreeRebuilder:
def _get_doc(self, node: T_Doc) -> Tuple[T_Doc, Optional[str]]:
try:
if PY37_PLUS and hasattr(node, "docstring"):
- doc = node.docstring
+ doc = node.docstring # type: ignore[union-attr,attr-defined] # mypy doesn't recognize hasattr
return node, doc
if node.body and isinstance(node.body[0], self._module.Expr):
@@ -805,6 +805,7 @@ class TreeRebuilder:
if self._global_names and node.name in self._global_names[-1]:
node.root().set_local(node.name, node)
else:
+ assert node.parent
node.parent.set_local(node.name, node)
def visit_arg(self, node: "ast.arg", parent: NodeNG) -> nodes.AssignName:
@@ -882,6 +883,7 @@ class TreeRebuilder:
type_comment_posonlyargs=type_comment_posonlyargs,
)
# save argument names in locals:
+ assert newnode.parent
if vararg:
newnode.parent.set_local(vararg, newnode)
if kwarg:
@@ -954,6 +956,9 @@ class TreeRebuilder:
# Invalid type comment, just skip it.
return None
+ if not type_comment_ast:
+ return None
+
returns: Optional[NodeNG] = None
argtypes: List[NodeNG] = [
self.visit(elem, parent) for elem in (type_comment_ast.argtypes or [])
@@ -1615,7 +1620,9 @@ class TreeRebuilder:
)
# Prohibit a local save if we are in an ExceptHandler.
if not isinstance(parent, nodes.ExceptHandler):
- self._delayed_assattr.append(newnode)
+ # mypy doesn't recognize that newnode has to be AssignAttr because it doesn't support ParamSpec
+ # See https://github.com/python/mypy/issues/8645
+ self._delayed_assattr.append(newnode) # type: ignore[arg-type]
else:
# pylint: disable-next=else-if-used
# Preserve symmetry with other cases
@@ -2365,7 +2372,7 @@ class TreeRebuilder:
self, node: "ast.MatchSingleton", parent: NodeNG
) -> nodes.MatchSingleton:
return nodes.MatchSingleton(
- value=node.value,
+ value=node.value, # type: ignore[arg-type] # See https://github.com/python/mypy/pull/10389
lineno=node.lineno,
col_offset=node.col_offset,
end_lineno=node.end_lineno,