File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 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:
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
12261231 # RawExpressionType so we just pass in 'None' for now. We'll report the
12271232 # appropriate error at a later stage.
12281233 numeric_value = None
1229- type_name = 'builtins.{}' .format (type (n . n ).__name__ )
1234+ type_name = 'builtins.{}' .format (type (value ).__name__ )
12301235 return RawExpressionType (
12311236 numeric_value ,
12321237 type_name ,
You can’t perform that action at this time.
0 commit comments