8000 gh-105144: Runtime-checkable protocols: move all 'sanity checks' to `_ProtocolMeta.__subclasscheck__` by AlexWaygood · Pull Request #105152 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105144: Runtime-checkable protocols: move all 'sanity checks' to _ProtocolMeta.__subclasscheck__ #105152

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

Merged
merged 4 commits into from
May 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
AlexWaygood committed May 31, 2023
commit 3b56274c3d6a846ceaf02145ab89f44190cd6e3b
6 changes: 3 additions & 3 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ def _caller(depth=1, default='__main__'):
pass
return None

def _allow_reckless_class_checks(depth=3):
def _allow_reckless_class_checks(depth=2):
"""Allow instance and class checks for special stdlib modules.

The abc and functools modules indiscriminately call isinstance() and
Expand Down Expand Up @@ -1787,7 +1787,7 @@ def __subclasscheck__(cls, other):
raise TypeError('issubclass() arg 1 must be a class')
if (
getattr(cls, '_is_protocol', False)
and not _allow_reckless_class_checks(depth=2)
and not _allow_reckless_class_checks()
):
if not cls.__callable_proto_members_only__:
raise TypeError(
Expand All @@ -1809,7 +1809,7 @@ def __instancecheck__(cls, instance):

if (
not getattr(cls, '_is_runtime_protocol', False) and
not _allow_reckless_class_checks(depth=2)
not _allow_reckless_class_checks()
):
raise TypeError("Instance and class checks can only be used with"
" @runtime_checkable protocols")
Expand Down
0