Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Comment thread
AlexWaygood marked this conversation as 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