Skip to content
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-70647: Add detail to error message when parsing a bad day of month. #116184

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Mar 1, 2024

The presence of the values in the error message gives a stronger hint as to what went wrong.

>>> datetime.strptime("2.29", "%m.%d")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    datetime.strptime("2.29", "%m.%d")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ".../Lib/_strptime.py", line 565, in _strptime_datetime
    return cls(*args)
           ~~~^^^^^^^
ValueError: day 29 is out of range for month 2 in year 1900

… month.

The presence of the values in the error message gives a stronger hint as
to what went wrong.

```
>>> datetime.strptime("2.29", "%m.%d")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    datetime.strptime("2.29", "%m.%d")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ".../Lib/_strptime.py", line 565, in _strptime_datetime
    return cls(*args)
           ~~~^^^^^^^
ValueError: day 29 is out of range for month 2 in year 1900
```
@pitrou
Copy link
Member

pitrou commented Mar 1, 2024

+1 on the principle, but ideally there would be a test for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants