@@ -107,7 +107,7 @@ def __init__(
107
107
def _get_doc (self , node : T_Doc ) -> Tuple [T_Doc , Optional [str ]]:
108
108
try :
109
109
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
111
111
return node , doc
112
112
if node .body and isinstance (node .body [0 ], self ._module .Expr ):
113
113
@@ -805,6 +805,7 @@ def _save_assignment(self, node: Union[nodes.AssignName, nodes.DelName]) -> None
805
805
if self ._global_names and node .name in self ._global_names [- 1 ]:
806
806
node .root ().set_local (node .name , node )
807
807
else :
808
+ assert node .parent
808
809
node .parent .set_local (node .name , node )
809
810
810
811
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
882
883
type_comment_posonlyargs = type_comment_posonlyargs ,
883
884
)
884
885
# save argument names in locals:
886
+ assert newnode .parent
885
887
if vararg :
886
888
newnode .parent .set_local (vararg , newnode )
887
889
if kwarg :
@@ -954,6 +956,9 @@ def check_function_type_comment(
954
956
# Invalid type comment, just skip it.
955
957
return None
956
958
959
+ if not type_comment_ast :
960
+ return None
961
+
957
962
returns : Optional [NodeNG ] = None
958
963
argtypes : List [NodeNG ] = [
959
964
self .visit (elem , parent ) for elem in (type_comment_ast .argtypes or [])
@@ -1615,7 +1620,9 @@ def visit_attribute(
1615
1620
)
1616
1621
# Prohibit a local save if we are in an ExceptHandler.
1617
1622
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]
1619
1626
else :
1620
1627
# pylint: disable-next=else-if-used
1621
1628
# Preserve symmetry with other cases
@@ -2365,7 +2372,7 @@ def visit_matchsingleton(
2365
2372
self , node : "ast.MatchSingleton" , parent : NodeNG
2366
2373
) -> nodes .MatchSingleton :
2367
2374
return nodes .MatchSingleton (
2368
- value = node .value ,
2375
+ value = node .value , # type: ignore[arg-type] # See https://github.com/python/mypy/pull/10389
2369
2376
lineno = node .lineno ,
2370
2377
col_offset = node .col_offset ,
2371
2378
end_lineno = node .end_lineno ,
0 commit comments