KotlinIsland / basedmypy

Based Python static type checker with baseline, sane default settings and based typing features
Other
134 stars 4 forks source link

Infer exact types #202

Open KotlinIsland opened 2 years ago

KotlinIsland commented 2 years ago
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 commented 1 month ago

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

class A: ...
a = A()
a == A()  # i would expect an error here
jorenham commented 1 week ago

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

KotlinIsland commented 1 week ago

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