Skip to content

Fix mypy warnings for astroid/rebuilder #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5173,7 +5173,7 @@ def __init__(
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,
Expand Down
13 changes: 10 additions & 3 deletions astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
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):

Expand Down Expand Up @@ -805,6 +805,7 @@ def _save_assignment(self, node: Union[nodes.AssignName, nodes.DelName]) -> None
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:
Expand Down Expand Up @@ -882,6 +883,7 @@ def visit_arguments(self, node: "ast.arguments", parent: NodeNG) -> nodes.Argume
type_comment_posonlyargs=type_comment_posonlyargs,
)
# save argument names in locals:
assert newnode.parent
if vararg:
newnode.parent.set_local(vararg, newnode)
if kwarg:
Expand Down Expand Up @@ -954,6 +956,9 @@ def check_function_type_comment(
# 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 [])
Expand Down Expand Up @@ -1615,7 +1620,9 @@ def visit_attribute(
)
# 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
Expand Down Expand Up @@ -2365,7 +2372,7 @@ def visit_matchsingleton(
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,
Expand Down