Content-Length: 271322 | pFad | http://github.com/python/cpython/pull/105239/commits/b85a3205c4b22942c9cb4ce0f8619d7b04d2ffe0

5E gh-105237: Allow calling `issubclass(X, typing.Protocol)` again by AlexWaygood · Pull Request #105239 · python/cpython · GitHub
Skip to content
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

gh-105237: Allow calling issubclass(X, typing.Protocol) again #105239

Merged
merged 6 commits into from
Jun 5, 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
Cleaner solution
  • Loading branch information
AlexWaygood committed Jun 2, 2023
commit b85a3205c4b22942c9cb4ce0f8619d7b04d2ffe0
6 changes: 4 additions & 2 deletions Lib/typing.py
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,8 @@ def __subclasscheck__(cls, other):
def __instancecheck__(cls, instance):
# We need this method for situations where attributes are
# assigned in __init__.
if cls is Protocol:
return type.__instancecheck__(cls, instance)
if not getattr(cls, "_is_protocol", False):
# i.e., it's a concrete subclass of a protocol
return super().__instancecheck__(instance)
Expand Down Expand Up @@ -1864,7 +1866,7 @@ def meth(self) -> T:
...
"""
__slots__ = ()
_is_protocol = False
_is_protocol = True
_is_runtime_protocol = False

def __init_subclass__(cls, *args, **kwargs):
Expand Down Expand Up @@ -1906,7 +1908,7 @@ def _proto_hook(other):

# ... otherwise check consistency of bases, and prohibit instantiation.
for base in cls.__bases__:
if not (base in {object, Generic, Protocol} or
if not (base in (object, Generic) or
base.__module__ in _PROTO_ALLOWLIST and
base.__name__ in _PROTO_ALLOWLIST[base.__module__] or
issubclass(base, Generic) and getattr(base, '_is_protocol', False)):
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/105239/commits/b85a3205c4b22942c9cb4ce0f8619d7b04d2ffe0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy