Skip to content

Infer exact types #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KotlinIsland opened this issue Feb 20, 2022 · 3 comments
Open

Infer exact types #202

KotlinIsland opened this issue Feb 20, 2022 · 3 comments

Comments

@KotlinIsland
Copy link
Owner

KotlinIsland commented Feb 20, 2022

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
Copy link
Owner Author

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

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

@jorenham
Copy link
Collaborator

jorenham commented Sep 6, 2024

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

@KotlinIsland
Copy link
Owner Author

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

@KotlinIsland KotlinIsland added the p-1 high label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants