-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-120782: Update internal type cache when reloading datetime #120829
Conversation
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
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.
Thanks!
_datetime.time.max > _datetime.time.min | ||
_datetime.datetime.max > _datetime.datetime.min | ||
_datetime.timedelta.max > _datetime.timedelta.min | ||
isinstance(_datetime.timezone.min, _datetime.tzinfo) |
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.
Should this have assert
?
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.
assert isinstance(_datetime.timezone.min, _datetime.tzinfo)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
assert not isinstance(_datetime.timezone.min, _datetime.tzinfo)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Both fail, so this checks if it crashes or not. I agree this is not a good example.
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.
Given that the code looks a bit unusual, it would be worth adding a brief comment explaining that.
(Sorry I didn't notice this during my earlier review. Good catch, @JelleZijlstra.)
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.
Wouldn't it make sense to have these asserts actually check that the values are of the type they should be? The bug manifested itself as these values appearing to be objects of various random types.
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.
You could also assert that timezone.__dict__["min"] is timezone.min
.
Thanks. I'll make a backport PR to 3.13 manually with an assertion to the test case. |
GH-120855 is a backport of this pull request to the 3.13 branch. |
…H-120829) (#120855) * [3.13] gh-120782: Update internal type cache when reloading datetime When reloading _datetime module, the single-phase version did not invoke the PyInit__datetime function, whereas the current multi-phase version updates the static types through the module init. The outdated static type cache in the interpreter state needs to be invalidated at the end of reloading the multi-phase module.
|
When reloading
_datetime
module, the single-phase version did not invoke thePyInit__datetime
function, whereas the current multi-phase version updates the static types through the module init. The outdated static type cache in the interpreter state needs to be invalidated at the end of reloading the multi-phase module.test_datetime
fails with a--forever
argument #120782