-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
_py_abc
breaks pattern matching
#89646
Comments
Pure Python class that has been registered as a For example:
It seems to be caused by 069e81a , only |
This is also an issue for I'm happy to help with a PR if there's a good idea on how to improve this. |
The root of the issue is that the While So how do we do this without I guess the problem boils down to: how can a pure-Python class set these flags correctly without some sort of C helper? Until we can answer that question, pattern matching can't work correctly with Half-baked idea: maybe |
collections.abc.Sequence
can't be recgnized by the match statement without the _abc
module_py_abc
breaks pattern matching
Writable Can we introduce 4 private functions in sys._register_tpflags_mapping(tp: type) -> None
sys._register_tpflags_sequence(tp: type) -> None
sys._check_tpflags_mapping(tp: type) -> bool
sys._check_tpflags_sequence(tp: type) -> bool We can explitly document them as private and not recommanded to use, or just not document them. They will be CPython implementation detail. These 4 functions will be called in @classmethod
def register(cls, subclass):
type(cls).register(cls, subclass)
sys._register_tpflags_mapping(subclass) # or sequence
@classmethod
def __subclasshook__(cls, subclass):
if sys._check_tpflags_mapping(subclass): # or sequence
return True
return NotImplemented And the current |
Apologies if this is a dumb question but under which circumstances is It seems to me just removing the fallback to the Python version would have the same effect, but I can only assume the Python implementation was left in for a reason (perhaps some platform I'm not familiar with). |
The one and only one obvious way to do it would still be to register/inherit I'm usually not a big fan of using |
I'm sort of wondering that too. I know that lots of these pure-Python copies are kept around for platforms or implementations that can't build or use the C accelerators for some reason. I'm curious if anybody out there is actually using |
Maybe PyPy would use it. |
You are right. Polluting
I'm not sure either. IMO the reason may be PEP 399, which specifies that:
But it also says:
Obviously |
The PyPy also provides a built-in
I suggest that we do not add a workaround for this edge case and rather document that |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: