Skip to content

Commit ceedd28

Browse files
committed
Fix another "complex" typed_ast interaction
This is just a case I missed in #6169.
1 parent 307949a commit ceedd28

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mypy/fastparse.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,13 @@ def visit_UnaryOp(self, n: UnaryOp) -> Type:
12181218

12191219
# Num(number n)
12201220
def visit_Num(self, n: Num) -> Type:
1221-
if isinstance(n.n, int):
1222-
numeric_value = n.n
1221+
# The n field has the type complex, but complex isn't *really*
1222+
# a parent of int and float, and this causes isinstance below
1223+
# to think that the complex branch is always picked. Avoid
1224+
# this by throwing away the type.
1225+
value = n.n # type: object
1226+
if isinstance(value, int):
1227+
numeric_value = value # type: Optional[int]
12231228
type_name = 'builtins.int'
12241229
else:
12251230
# Other kinds of numbers (floats, complex) are not valid parameters for

0 commit comments

Comments
 (0)