From 9c3af43f382d1fd316a5593d77023bcc70dde0f5 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sun, 28 Sep 2025 14:01:09 -0400 Subject: [PATCH] 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 --- Lib/_collections_abc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index 60b471317ce97c..44d930a0dd6616 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -106,11 +106,11 @@ async def _ag(): yield ### ONE-TRICK PONIES ### def _check_methods(C, *methods): - mro = C.__mro__ + mro_dicts = [B.__dict__ for B in C.__mro__] for method in methods: - for B in mro: - if method in B.__dict__: - if B.__dict__[method] is None: + for base_dict in mro_dicts: + if method in base_dict: + if base_dict[method] is None: return NotImplemented break else: