| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…asses A more invasive solution for python#105144; perhaps better kept for 3.13 only.
| if issubclass(subclass, rcls): | ||
| cls._abc_cache.add(subclass) | ||
| return True | ||
| except Exception: |
There was a problem hiding this comment.
In the C code I actually suppress all exceptions, not just Exception. Not sure what the right thing to do is.
Sorry, something went wrong.
There was a problem hiding this comment.
I'd say suppressing all exceptions would definitely be bad -- that would mean that we'd be suppressing e.g. KeyboardInterrupt, and SystemExit.
Honestly, I feel pretty uncomfortable about suppressing all subclasses of Exception -- could we just do TypeError? If I had a typo in a custom __subclasscheck__ method, I'm not sure I'd want e.g. the resulting AttributeError to be silenced because of the fact that ABCMeta was being used somewhere
Sorry, something went wrong.
There was a problem hiding this comment.
You'd still see the error if you use your broken class directly. What this PR changes is that you'll no longer see the error if you use issubclass() checks on a separate class that inherits from the same ABC.
Sorry, something went wrong.
|
Looks like there's still lots of test_typing failures if I apply this diff to your PR branch: diff --git a/Lib/typing.py b/Lib/typing.py
index 8c874797d2..8caeb915d8 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1733,7 +1733,7 @@ def _allow_reckless_class_checks(depth=3):
The abc and functools modules indiscriminately call isinstance() and
issubclass() on the whole MRO of a user class, which may contain protocols.
"""
- return _caller(depth) in {'abc', 'functools', None}
+ return _caller(depth) in {'functools', None} |
Sorry, something went wrong.
|
The trouble is that these __subclasscheck__ calls call into _ProtocolMeta.__subclasscheck__, which might raise: Lines 105 to 106 in ec0082c But we don't want it to raise if the __subclasscheck__ call is coming from an __instancecheck__ call. |
Sorry, something went wrong.
|
Ultimately, it does sort of feel like typing is the module that's "in the wrong" here. The abc module makes the assumption that issubclass() calls will never raise, providing both arguments are instances of type. That's true for the vast majority of classes, so I think it's a reasonable assumption to make. typing is the module that's doing a surprising/unusual thing here, so it seems reasonable to say that it's typing that should have to do the awkward workaround. It's unfortunate how fragile that makes some of the code in typing.py, but I think PEP-544's semantics are too well-established now to change the behaviour. |
Sorry, something went wrong.
|
I feel like this change isn't worth the churn. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
A more invasive solution for #105144; perhaps better kept for 3.13 only.