You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
datetime error message is different between _pydatetime.py and _datetimemodule.c #109798
import_datetime, _pydatetime_datetime.date(1, 1, 50)
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>ValueError: dayisoutofrangeformonth```
_pydatetime.date(1, 1, 50)
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/usr/lib/python3.12/_pydatetime.py", line960, in__new__year, month, day=_check_date_fields(year, month, day)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/usr/lib/python3.12/_pydatetime.py", line535, in_check_date_fieldsraiseValueError('day must be in 1..%d'%dim, day)
ValueError: ('day must be in 1..31', 50)
The error message differs between the two implementations of datetime. This came up when testing PyPy, which uses the pure-python datetime implementation. xref conda-forge/rtoml-feedstock#1 (comment)
Ok, I will leave error message as in the c implementation
Firstly, it is better to output a string (not tuple), and in the python implementation, the second value in tuple is redundant.
Secondly, it seems to me that it is the main implementation.
I also add more inconsistency in the error messages that I found in the code
1. Errors about date and time have inconsistent messages, for example problem with year field may raise next errors:
ValueError: ('year must be in 1..9999', {year})
ValueError: Yearisoutofrange: {year}
ValueError: year {year} isoutofrangeValueError: Year {year} isoutofrange
We need to make same message template for the fields year, month, day, hour, minute, second, microsecond and fold.
2. Method date.fromisocalendar may raise next errors depends on implementation:
3. Error with offset argument in timezone may raise next errors:
ValueError: offsetmustbeatimedeltastrictlybetween-timedelta(hours=24) andtimedelta(hours=24), notdatetime.timedelta(days=21). # with dotValueError: offsetmustbeatimedeltastrictlybetween-timedelta(hours=24) andtimedelta(hours=24), notdatetime.timedelta(days=21) # without dotValueError: offsetmustbeatimedeltastrictlybetween-timedelta(hours=24) andtimedelta(hours=24).
ValueError: {name}()={offset}, mustbeatimedeltastrictlybetween-timedelta(hours=24) andtimedelta(hours=24)
4. Errors about type of arugment
for example if i call _pydatetime.datetime() and _datetime.datetime() with tz i get:
TypeError: tzinfoargumentmustbeNoneorofatzinfosubclass# in _pydatetimeTypeError: tzinfoargumentmustbeNoneorofatzinfosubclass, nottype'int'# in _datetime
Activity
donbarbos commentedon Nov 25, 2024
@mattip So, you suggest to leave the option as in the
_datetimeimplementation?I can send a PR
mattip commentedon Nov 27, 2024
I don't really have an opinion which error message is better, only that they be the same.
donbarbos commentedon Nov 27, 2024
Ok, I will leave error message as in the c implementation
Firstly, it is better to output a string (not tuple), and in the python implementation, the second value in tuple is redundant.
Secondly, it seems to me that it is the main implementation.
donbarbos commentedon Nov 27, 2024
I also add more inconsistency in the error messages that I found in the code
1. Errors about date and time have inconsistent messages, for example problem with
yearfield may raise next errors:We need to make same message template for the fields
year,month,day,hour,minute,second,microsecondandfold.2. Method
date.fromisocalendarmay raise next errors depends on implementation:3. Error with offset argument in timezone may raise next errors:
4. Errors about type of arugment
for example if i call
_pydatetime.datetime()and_datetime.datetime()with tz i get:gh-109798: Normalize `_datetime` and `datetime` error messages (#127345)
StanFromIreland commentedon Mar 10, 2025
PR was merged, issue is complete :-)
It seems there was no plan to back port which is for the best for backwards compatibility.
mattip commentedon Mar 11, 2025
Thanks!