@@ -1079,14 +1079,14 @@ def _no_init(self, *args, **kwargs):
10791079 raise TypeError ('Protocols cannot be instantiated' )
10801080
10811081
1082- def _allow_reckless_class_checks ( depth = 3 ):
1082+ def _allow_reckless_class_cheks ( ):
10831083 """Allow instance and class checks for special stdlib modules.
10841084
10851085 The abc and functools modules indiscriminately call isinstance() and
10861086 issubclass() on the whole MRO of a user class, which may contain protocols.
10871087 """
10881088 try :
1089- return sys ._getframe (depth ).f_globals ['__name__' ] in ['abc' , 'functools' ]
1089+ return sys ._getframe (3 ).f_globals ['__name__' ] in ['abc' , 'functools' ]
10901090 except (AttributeError , ValueError ): # For platforms without _getframe().
10911091 return True
10921092
@@ -1106,14 +1106,6 @@ class _ProtocolMeta(ABCMeta):
11061106 def __instancecheck__ (cls , instance ):
11071107 # We need this method for situations where attributes are
11081108 # assigned in __init__.
1109- if (
1110- getattr (cls , '_is_protocol' , False ) and
1111- not getattr (cls , '_is_runtime_protocol' , False ) and
1112- not _allow_reckless_class_checks (depth = 2 )
1113- ):
1114- raise TypeError ("Instance and class checks can only be used with"
1115- " @runtime_checkable protocols" )
1116-
11171109 if ((not getattr (cls , '_is_protocol' , False ) or
11181110 _is_callable_members_only (cls )) and
11191111 issubclass (instance .__class__ , cls )):
@@ -1176,12 +1168,12 @@ def _proto_hook(other):
11761168
11771169 # First, perform various sanity checks.
11781170 if not getattr (cls , '_is_runtime_protocol' , False ):
1179- if _allow_reckless_class_checks ():
1171+ if _allow_reckless_class_cheks ():
11801172 return NotImplemented
11811173 raise TypeError ("Instance and class checks can only be used with"
11821174 " @runtime_checkable protocols" )
11831175 if not _is_callable_members_only (cls ):
1184- if _allow_reckless_class_checks ():
1176+ if _allow_reckless_class_cheks ():
11851177 return NotImplemented
11861178 raise TypeError ("Protocols with non-method members"
11871179 " don't support issubclass()" )
0 commit comments