From 7685d0050b6d52807ce393a457a1cea85ec29c26 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 8 Jan 2019 16:51:38 -0800 Subject: [PATCH] Fix another "complex" typed_ast interaction This is just a case I missed in #6169. --- mypy/fastparse.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 413af5a8c08f..690cbe9ee6d2 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1218,15 +1218,20 @@ def visit_UnaryOp(self, n: UnaryOp) -> Type: # Num(number n) def visit_Num(self, n: Num) -> Type: - if isinstance(n.n, int): - numeric_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 + if isinstance(value, int): + numeric_value = value # type: Optional[int] type_name = 'builtins.int' else: # Other kinds of numbers (floats, complex) are not valid parameters for # RawExpressionType so we just pass in 'None' for now. We'll report the # appropriate error at a later stage. numeric_value = None - type_name = 'builtins.{}'.format(type(n.n).__name__) + type_name = 'builtins.{}'.format(type(value).__name__) return RawExpressionType( numeric_value, type_name,