diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 15122012a0dc..413af5a8c08f 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -928,7 +928,11 @@ def visit_Call(self, n: Call) -> CallExpr: # Num(object n) -- a number as a PyObject. def visit_Num(self, n: ast3.Num) -> Union[IntExpr, FloatExpr, ComplexExpr]: - val = n.n + # The n field has the type complex, but complex isn't *really* + # a parent of int and float, and this causes isinstance below + # to think that the complex branch is always picked. Avoid + # this by throwing away the type. + val = n.n # type: object if isinstance(val, int): e = IntExpr(val) # type: Union[IntExpr, FloatExpr, ComplexExpr] elif isinstance(val, float): diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py index 876864796ebe..8100c316ea30 100644 --- a/mypy/fastparse2.py +++ b/mypy/fastparse2.py @@ -902,7 +902,11 @@ def visit_Call(self, n: Call) -> CallExpr: # Num(object n) -- a number as a PyObject. def visit_Num(self, n: ast27.Num) -> Expression: - value = n.n + # The n field has the type complex, but complex isn't *really* + # a parent of int and float, and this causes isinstance below + # to think that the complex branch is always picked. Avoid + # this by throwing away the type. + value = n.n # type: object is_inverse = False if str(n.n).startswith('-'): # Hackish because of complex. value = -n.n