8000 gh-109798: Normalize `_datetime` and `datetime` error messages by donBarbos · Pull Request #127345 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-109798: Normalize _datetime and datetime error messages #127345

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

Merged
merged 31 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
764eb1b
Update error messages to be the same in datetime
donBarbos Nov 27, 2024
2bf419f
Add NEWS.d/next
donBarbos Nov 27, 2024
4363e9e
fixed syntax errors
donBarbos Nov 27, 2024
9da0dfc
Move Py_DECREF after PyErr_Format
donBarbos Nov 29, 2024
179423d
Add more info in message error in _pydatetime impl
donBarbos Nov 29, 2024
f691251
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
d8973cf
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
5eea62f
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
79543cc
Update Modules/_datetimemodule.c for optimisation
donBarbos Nov 29, 2024
d174497
Revert last update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
498c4ba
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
216d0fe
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
c409fec
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
3f454f6
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
a2b8f7a
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
209c338
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
0777aa5
Update Misc/NEWS.d/next/Library/2024-11-27-23-29-05.gh-issue-109798.O…
donBarbos Nov 30, 2024
4d31d33
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
f05ebba
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
f840105
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
61c95a5
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
2ab77b3
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
b1e272a
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
7a35bd4
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
cfd18cb
Add tests
donBarbos Nov 30, 2024
2827514
Update _pydatetime.py
donBarbos Dec 1, 2024
cd3bdc1
Update _pydatetime.py
donBarbos Dec 1, 2024
9915dfe
Change but got to not
donBarbos Dec 1, 2024
1da5a3a
Correct line break
donBarbos Dec 1, 2024
610f067
Update 2024-11-27-23-29-05.gh-issue-109798.OPj1CT.rst
pganssle Feb 12, 2025
410e0ce
Merge branch 'main' into issue-109798
pganssle Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Lib/_pydatetime.py
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
  • Loading branch information
donBarbos and ZeroIntensity authored Nov 30, 2024
commit f84010575eb911e6561f5aacab9a5fceff3418a2
2 changes: 1 addition & 1 deletion Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,7 @@ def __new__(cls, offset, name=_Omitted):
if not cls._minoffset <= offset <= cls._maxoffset:
raise ValueError("offset must be a timedelta "
"strictly between -timedelta(hours=24) and "
f"timedelta(hours=24), not {offset.__repr__()}")
f"timedelta(hours=24), not {offset!r}")
Copy link
Member

Choose a reason for 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.

Copy link
Contributor Author
@donBarbos donBarbos Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pganssle
Okay, then let's solve this issue in a separate PR linked to that issue (I can send the changes soon).
I think this one can be merged for now and I would be glad if you review another PR #127242 for datetime module :)

return cls._create(offset, name)

def __init_subclass__(cls):
Expand Down
Loading
0