Skip to content

Commit 3a1cdb0

Browse files
DanielNoordcdce8p
andauthored
Fix mypy warnings for astroid/rebuilder (#1244)
Co-authored-by: Marc Mueller <[email protected]>
1 parent 4443159 commit 3a1cdb0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

astroid/nodes/node_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5184,7 +5184,7 @@ def __init__(
51845184
end_col_offset: Optional[int] = None,
51855185
parent: Optional[NodeNG] = None,
51865186
) -> None:
5187-
self.value: Literal[True, False, None] = value
5187+
self.value = value
51885188
super().__init__(
51895189
lineno=lineno,
51905190
col_offset=col_offset,

astroid/rebuilder.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(
107107
def _get_doc(self, node: T_Doc) -> Tuple[T_Doc, Optional[str]]:
108108
try:
109109
if PY37_PLUS and hasattr(node, "docstring"):
110-
doc = node.docstring
110+
doc = node.docstring # type: ignore[union-attr,attr-defined] # mypy doesn't recognize hasattr
111111
return node, doc
112112
if node.body and isinstance(node.body[0], self._module.Expr):
113113

@@ -805,6 +805,7 @@ def _save_assignment(self, node: Union[nodes.AssignName, nodes.DelName]) -> None
805805
if self._global_names and node.name in self._global_names[-1]:
806806
node.root().set_local(node.name, node)
807807
else:
808+
assert node.parent
808809
node.parent.set_local(node.name, node)
809810

810811
def visit_arg(self, node: "ast.arg", parent: NodeNG) -> nodes.AssignName:
@@ -882,6 +883,7 @@ def visit_arguments(self, node: "ast.arguments", parent: NodeNG) -> nodes.Argume
882883
type_comment_posonlyargs=type_comment_posonlyargs,
883884
)
884885
# save argument names in locals:
886+
assert newnode.parent
885887
if vararg:
886888
newnode.parent.set_local(vararg, newnode)
887889
if kwarg:
@@ -954,6 +956,9 @@ def check_function_type_comment(
954956
# Invalid type comment, just skip it.
955957
return None
956958

959+
if not type_comment_ast:
960+
return None
961+
957962
returns: Optional[NodeNG] = None
958963
argtypes: List[NodeNG] = [
959964
self.visit(elem, parent) for elem in (type_comment_ast.argtypes or [])
@@ -1615,7 +1620,9 @@ def visit_attribute(
16151620
)
16161621
# Prohibit a local save if we are in an ExceptHandler.
16171622
if not isinstance(parent, nodes.ExceptHandler):
1618-
self._delayed_assattr.append(newnode)
1623+
# mypy doesn't recognize that newnode has to be AssignAttr because it doesn't support ParamSpec
1624+
# See https://github.com/python/mypy/issues/8645
1625+
self._delayed_assattr.append(newnode) # type: ignore[arg-type]
16191626
else:
16201627
# pylint: disable-next=else-if-used
16211628
# Preserve symmetry with other cases
@@ -2365,7 +2372,7 @@ def visit_matchsingleton(
23652372
self, node: "ast.MatchSingleton", parent: NodeNG
23662373
) -> nodes.MatchSingleton:
23672374
return nodes.MatchSingleton(
2368-
value=node.value,
2375+
value=node.value, # type: ignore[arg-type] # See https://github.com/python/mypy/pull/10389
23692376
lineno=node.lineno,
23702377
col_offset=node.col_offset,
23712378
end_lineno=node.end_lineno,

0 commit comments

Comments
 (0)