File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -1218,15 +1218,20 @@ def visit_UnaryOp(self, n: UnaryOp) -> Type:
1218
1218
1219
1219
# Num(number n)
1220
1220
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]
1223
1228
type_name = 'builtins.int'
1224
1229
else :
1225
1230
# Other kinds of numbers (floats, complex) are not valid parameters for
1226
1231
# RawExpressionType so we just pass in 'None' for now. We'll report the
1227
1232
# appropriate error at a later stage.
1228
1233
numeric_value = None
1229
- type_name = 'builtins.{}' .format (type (n . n ).__name__ )
1234
+ type_name = 'builtins.{}' .format (type (value ).__name__ )
1230
1235
return RawExpressionType (
1231
1236
numeric_value ,
1232
1237
type_name ,
You can’t perform that action at this time.
0 commit comments