Created
December 12, 2019 20:54
-
-
Save davidfraser/ac8706bb876f4bc30234c4f44c7a4cfb to your computer and use it in GitHub Desktop.
Patches CPython's _weakrefset.py to prevent a spurious TypeError when adding an item to a WeakSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patches WeakSet.add to prevent it having a spurious error if a weak ref goes away between calling this function and adding it | |
This is done analogously to the patch in https://github.com/python/cpython/commit/f8de3fea1280d55377d40c6e04b64114f9da2fa6: | |
"#10360: catch TypeError in WeakSet.__contains__, just like WeakKeyDictionary does." | |
See https://bugs.python.org/issue10360 for infomration on that | |
@@ -83,7 +83,11 @@ | |
def add(self, item): | |
if self._pending_removals: | |
self._commit_removals() | |
- self.data.add(ref(item, self._remove)) | |
+ try: | |
+ self.data.add(ref(item, self._remove)) | |
+ except TypeError: | |
+ #Can't add to the cache if ref doesn't exist | |
+ pass | |
def clear(self): | |
if self._pending_removals: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment