basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Infer exact types

Open KotlinIsland opened this issue 3 years ago • 3 comments

class A: ...
A() or 1 # error, we know that it's not a subtype that has an `__eq__`
reveal_type(A())  # Exactly[A]
def f(a: A):
    a or 1 # no error
    reveal_type(a)  # A
class A: ...
class B(A): ...
isinstance(A(), B) # error
reveal_type(A())  # Exactly[A]
def f(a: A):
    isinstance(a, B) # no error
    reveal_type(a)  # A

Would provide a lot of benefits in terms of 'type tightness'(strict-equality).

KotlinIsland avatar Feb 20 '22 10:02 KotlinIsland

as a more paranoid version, exact types could become instance specific

class A: ...
a = A()
a == A()  # i would expect an error here

KotlinIsland avatar Aug 15 '24 08:08 KotlinIsland

Would this Exact be able to solve the not_an_int: complex = int cringe-fest 😲?

jorenham avatar Sep 06 '24 10:09 jorenham

I think that would be better solved by deleting promotions. but yes, it would help a lot

  • #167

KotlinIsland avatar Sep 06 '24 11:09 KotlinIsland