basedmypy
basedmypy copied to clipboard
Infer exact types
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).
as a more paranoid version, exact types could become instance specific
class A: ...
a = A()
a == A() # i would expect an error here
Would this Exact be able to solve the not_an_int: complex = int cringe-fest 😲?
I think that would be better solved by deleting promotions. but yes, it would help a lot
- #167