From c22edd02926b95f5b8b6f96d9f49d3213d053e28 Mon Sep 17 00:00:00 2001 From: KotlinIsland <65446343+kotlinisland@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:56:59 +1000 Subject: [PATCH] wip --- mypy/typeanal.py | 6 ++++ test-data/unit/check-based-promotions.test | 40 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test-data/unit/check-based-promotions.test diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 31f9b7a54..b9f2c964f 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -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( diff --git a/test-data/unit/check-based-promotions.test b/test-data/unit/check-based-promotions.test new file mode 100644 index 000000000..2b06ed3e1 --- /dev/null +++ b/test-data/unit/check-based-promotions.test @@ -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"