Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down