GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-109798: Normalize `_datetime` and `datetime` error messages by donbarbos · Pull Request #127345 · python/cpython Conversation
|
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
datetimedatetime
There was an error while loading. Please reload this page.
1d65305 to
9da0dfc
Compare
There was an error while loading. Please reload this page.
|
BTW, please do not force-push; it makes reviewing harder. Moreover, all commits are squashed upon merge anyway, so there's no need for the PR/branch to be cluttered with amendment commits. See also the devguide. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@erlend-aasland sorry, i got it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
datetime_datetime and datetime error messages
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks, and two notes:
PyErr_Format with %R can have unintended side effects if the __repr__ of the passed object is evil. Again, not a problem here as far as I can tell, but it's definitely worth noting.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Now, how far fetched is it to ask for some assertRaisesRegex tests 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ZeroIntensity i added tests ✅ , |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Getting close to ready :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| assert 1 <= month <= 12, f"month must be in 1..12, but got {month}" | ||
| return _DAYS_BEFORE_MONTH[month] + (month > 2 and _is_leap(year)) | ||
|
|
||
| def _ymd2ord(year, month, day): | ||
| "year, month, day -> ordinal, considering 01-Jan-0001 as day 1." | ||
| assert 1 <= month <= 12, 'month must be in 1..12' | ||
| assert 1 <= month <= 12, f"month must be in 1..12, but got {month}" | ||
| dim = _days_in_month(year, month) | ||
| assert 1 <= day <= dim, ('day must be in 1..%d' % dim) | ||
| assert 1 <= day <= dim, f"day must be in 1..{dim}, but got {day}" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth changing these to ifs and ValueErrors; assertions are disabled when Python is ran with -O. (Though, it's theoretically possible that will break code for people relying on AssertionError. I'm not sure how big of an issue that is.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the practice of calling assert is also found in other modules and I think this issue should be raised separately (not in this PR)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to do it in this PR, because IMO, unifying the error types fall under the category of "normalizing." I'm not super crazy about it though--any opinion @erlend-aasland?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
There was an error while loading. Please reload this page.
|
@erlend-aasland could you merge it? (if you have time :-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FYI, most of the core devs are done for the holidays. You'll have to wait until after the new year probably. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I strongly suspect that this is going to break people who are testing against exact error messages, but that's really not part of our public API, so that is fine.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| raise ValueError("offset must be a timedelta " | ||
| "strictly between -timedelta(hours=24) and " | ||
| "timedelta(hours=24).") | ||
| f"timedelta(hours=24), not {offset!r}") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Probably not going to be a great user experience here because of how bad the timedelta formatter is:
>>> print(f"{timedelta(hours=-25)!r}") datetime.timedelta(days=-2, seconds=82800)
Maybe it will be clearer if we do it this way:
if offset < timedelta(0): offset_str = f"-{-offset)}" else: offset_str = str(offset)
That will print stuff like -1 day, 1:00:00 instead of timedelta(days=-2, seconds=82800). Though looking at it, I realize that the way it gets printed is misleading, since that's the output you get from print(timedelta(hours=-23)) and users have no way of knowing what is going on under the hood there.
Probably a more elaborate timedelta formatter would be better, since we basically always want this in HH:MM:SS.fff format, since that reflects what we care about best and also is unambigous, but we don't have a particularly easy way to do that. I guess we can revisit this when/if #85426 is implemented.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pganssle CI successfully passed 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.