diff --git a/Lib/typing.py b/Lib/typing.py index 14845b36028ca1..911dcd096e7e7b 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1850,6 +1850,11 @@ def __instancecheck__(cls, instance): if super().__instancecheck__(instance): return True + # quick true negative check for protocols with many attributes. + if not hasattr(instance, '__getattr__'): + if not (cls.__protocol_attrs__ <= set(dir(instance))): + return False + getattr_static = _lazy_load_getattr_static() for attr in cls.__protocol_attrs__: try: