-
Notifications
You must be signed in to change notification settings - Fork 253
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
Fix TzInfo equality check based on offset #1197
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1197 +/- ##
=========================================
+ Coverage 0 90.25% +90.25%
=========================================
Files 0 106 +106
Lines 0 16352 +16352
Branches 0 36 +36
=========================================
+ Hits 0 14758 +14758
- Misses 0 1587 +1587
- Partials 0 7 +7
... and 105 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #1197 will improve performances by 24.38%Comparing Summary
Benchmarks breakdown
|
please review |
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! A few additional thoughts from me...
estdatetime = self.DT.replace(tzinfo=timezone(-timedelta(hours=5))) | ||
self.assertTrue(self.EST == estdatetime.tzinfo) | ||
self.assertTrue(tz > estdatetime.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.
I think we should add tests to confirm that comparisons with zoneinfo.ZoneInfo("Europe/London")
or similar don't succeed.
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.
Test added for zoneinfo.ZoneInfo
would check whether it return false. As, NotImplemented
would not throw error. there would be identity check eventually as __eq__
is not implemented for right-side and left-side. Would this be right way of doing this? Other option would be to throw NotImplementedError.
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.
I think by returning NotImplemented
then equality will return False
and ordering operators will raise a TypeError
. I see you added an equality test, maybe add a test that ordering throws TypeError
and then we're good here?
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.
Got it. Thank you so much @davidhewitt .
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.
Looks great, thanks!
Change Summary
comparison check doesn't works with
datatime.tzinfo
derived class- timezone. In this change, the comparison is based on offset set(in seconds) for tzinfo class.Related issue number
fix pydantic/pydantic#8683
Also partially fixes pydantic/pydantic#8195, in this the issue is that comparison check for different tzinfo fails.
is
.Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @adriangb