-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Should we remove sametypes.py? #7924
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
Comments
To be honest it's never been totally clear to me what it was for. |
It would be great if we can merge
Here are my proposed next steps if somebody wants to take this:
|
I think we should use
Again, there just should be an
I have a slightly different plan like gradually removing |
I still think that However, adding a new function that replaces Also, the names of various type functions are kind of confusing, but that'a a separate issue. |
Fixes #7924 So this is not 100% refactor, I make several semantic changes. As discussed in the issue, current implementation is not very principled, so I replace old complex logic with two options: * New `is_same_types()` is now located in `subtypes.py` and is doing two-way proper subtyping check. * Type equality with `==` can be used when we are checking for representation equality (used rarely, mostly for internal things) Btw this uncovered two actual bugs, one of which I fix here (two-line change), and leave a TODO for the second.
There are two ways we can compare types for being the same:
is_equivalent()
that just checksA <: B and B <: A
. This affects semantics of types in the user code being checked.Type.__eq__()
andType.__hash__()
. This affects internal bookkeeping, caching, etc.Currently,
is_same_types()
stays somewhere in the middle, it doesn't take into account some subtype relationships (including protocols and recursive type aliases), but it also "takes into account"make_simplified_union()
.I could see how this can be a minor performance optimization for equivalence with respect to proper subtyping, but IMO this kind of middle ground position increases chance for confusion and bugs. I would propose to remove it and instead use
==
andis_equivalent()
.The text was updated successfully, but these errors were encountered: