Skip to content

Commit 9c3af43

Browse files
feat: microoptimize _collections_abc._check_methods
We can reduce the number of attribute lookups requried here. I also think we can speed it up a little bit more if we make `methods` arg a packed tuple instead of an unpacked one since we can bypass the additional tuple creation at the time of each call Seeking input on that before I implement the same
1 parent 3779f2b commit 9c3af43

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/_collections_abc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ async def _ag(): yield
106106
### ONE-TRICK PONIES ###
107107

108108
def _check_methods(C, *methods):
109-
mro = C.__mro__
109+
mro_dicts = [B.__dict__ for B in C.__mro__]
110110
for method in methods:
111-
for B in mro:
112-
if method in B.__dict__:
113-
if B.__dict__[method] is None:
111+
for base_dict in mro_dicts:
112+
if method in base_dict:
113+
if base_dict[method] is None:
114114
return NotImplemented
115115
break
116116
else:

0 commit comments

Comments
 (0)