https://github.com/python/cpython/commit/cd4cfa6ed2fd5f866c7be339f1d3cf56aa4d2bad
commit: cd4cfa6ed2fd5f866c7be339f1d3cf56aa4d2bad
branch: main
author: d.grigonis <[email protected]>
committer: rhettinger <[email protected]>
date: 2024-05-11T15:55:23-05:00
summary:
gh-118932: ChainMap.__contains__ performance improvement (gh-118946)
files:
M Lib/collections/__init__.py
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index d06d84cbdfcc36..a17100e6c02a0e 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -1016,7 +1016,7 @@ def __getitem__(self, key):
return self.__missing__(key) # support subclasses that
define __missing__
def get(self, key, default=None):
- return self[key] if key in self else default
+ return self[key] if key in self else default # needs to make use of
__contains__
def __len__(self):
return len(set().union(*self.maps)) # reuses stored hash values if
possible
@@ -1028,7 +1028,10 @@ def __iter__(self):
return iter(d)
def __contains__(self, key):
- return any(key in m for m in self.maps)
+ for mapping in self.maps:
+ if key in mapping:
+ return True
+ return False
def __bool__(self):
return any(self.maps)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]