Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
elif fullname == "basedtyping.Intersection":
items = self.anal_array(t.args)
return IntersectionType.make_intersection(items)
elif fullname == "basedtyping.Int":
return self.named_type("builtins.int")
elif fullname == "basedtyping.Float":
return self.named_type("builtins.float")
elif fullname == "basedtyping.Complex":
return self.named_type("builtins.complex")
elif fullname == "typing.Optional":
if len(t.args) != 1:
self.fail(
Expand Down
40 changes: 40 additions & 0 deletions test-data/unit/check-based-promotions.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[case testInference]
i = 1
reveal_type(i) # N: Revealed type is "int"

c = 1j
reveal_type(c) # N: Revealed type is "complex | float | int"

f = 1.
reveal_type(f) # N: Revealed type is "float | int"


[case testBasedtypingImports]
from basedtyping import Int, Complex, Float

i: Int
i = 1
i = 1. # E: ...
i = ij # E: ...

c: Complex
c = 1 # E: ...
c = 1. # E: ...
c = 1j

f: Float
c = 1 # E: ...
c = 1.
c = 1j # E: ...


[case testDisable]
# flags: --disable-number-promotions
i = 1
reveal_type(i) # N: Revealed type is "int"

c = 1j
reveal_type(c) # N: Revealed type is "complex | float | int"

f = 1.
reveal_type(f) # N: Revealed type is "float | int"
Loading