-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-43132: Fix incorrect handling of PyObject_RichCompareBool() in _zoneinfo #24450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-43132: Fix incorrect handling of PyObject_RichCompareBool() in _zoneinfo #24450
Conversation
…oneinfo PyObject_RichCompareBool() returns -1 on error, but this case is not handled by the find_in_strong_cache() function. Any exception raised by PyObject_RichCompareBool() should be propagated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
GH-24457 is a backport of this pull request to the 3.9 branch. |
…oneinfo (pythonGH-24450) PyObject_RichCompareBool() returns -1 on error, but this case is not handled by the find_in_strong_cache() function. Any exception raised by PyObject_RichCompareBool() should be propagated. (cherry picked from commit effaec0) Co-authored-by: Zackery Spytz <[email protected]>
Um... I think this could use tests, no? |
…oneinfo (GH-24450) (GH-24457) PyObject_RichCompareBool() returns -1 on error, but this case is not handled by the find_in_strong_cache() function. Any exception raised by PyObject_RichCompareBool() should be propagated. (cherry picked from commit effaec0) Co-authored-by: Zackery Spytz <[email protected]>
|
I think you can trigger the
The other path I think is trickier to hit, and the consequence is a refleak, not a class Stringy(str):
def __new__(cls, value):
rv = super().__new__(cls, value)
rv.allow_comparisons = True
def __eq__(self, other):
if not self.allow_comparisons:
raise ComparisonError
return super().__eq__(other)
def __hash__(self):
return hash(self[:])
key = Stringy("America/New_York")
zoneinfo.ZoneInfo(key)
key.allow_comparisons = False
try:
# Note: This is try/except rather than assertRaises because there is no guarantee
# that the key is even still in the cache, or that the key for the cache is the original
# `key` object.
zoneinfo.ZoneInfo.clear_cache(only_keys="America/New_York")
except ComparisonError:
pass A possible alternative solution in the I guess we'll need a separate PR to add the tests, though. ☹ |
…oneinfo (pythonGH-24450) PyObject_RichCompareBool() returns -1 on error, but this case is not handled by the find_in_strong_cache() function. Any exception raised by PyObject_RichCompareBool() should be propagated.
PyObject_RichCompareBool() returns -1 on error, but this case is
not handled by the find_in_strong_cache() function. Any exception
raised by PyObject_RichCompareBool() should be propagated.
https://bugs.python.org/issue43132