Description
Bug report
Bug description:
As time.strftime doc says:
%Z: Time zone name (no characters if no time zone exists). Deprecated.
Some C libraries may replace %Z
with a null character, which may cause test_strptime.CalculationTests
to fail. For example:
ERROR: test_day_of_week_calculation (test.test_strptime.CalculationTests.test_day_of_week_calculation)
--
Traceback (most recent call last):
File "/data/ci/python3.12/lib/python3.12/test/test_strptime.py", line 563, in test_day_of_week_calculation
result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
^^
File "/data/ci/python3.12/lib/python3.12/_strptime.py", line 548, in _strptime_time
tt = _strptime(data_string, format)[0]
^^
File "/data/ci/python3.12/lib/python3.12/_strptime.py", line 333, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024 07 11 02 08 193 ' does not match format '%Y %m %d %H %S %j %Z'
In my opinion, removing the deprecated %Z
from format_string
variable will not affect those tests.
Similar tests that may fail:
test_strptime.CalculationTests.test_day_of_week_calculation
test_strptime.CalculationTests.test_gregorian_calculation
test_strptime.CalculationTests.test_julian_calculation
test_time.TimeTestCase.test_strptime
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Status
Activity
encukou commentedon Mar 13, 2025
encukou commentedon Jun 5, 2025
@CharlieZhao95, do you remember which C library this was?
We can't easily fix this without a reproducer.
CharlieZhao95 commentedon Jun 5, 2025
Thanks for the reminder, I missed the last message :)
I was working on a new unix-like embedded OS that uses musllibc. Now I think this case is more related to OS, maybe DST information is missing on the OS caused this error. And this is stated in the doc, I'm not sure if we should fix it.
See also:
musllibc strftime %Z
encukou commentedon Jun 5, 2025
A new OS! Exciting ❤️
But, on a new OS, you will generally need to skip a few tests, or patch things here and there.
If you really want to, send a PR and we could merge it. It shouldn't break supported platforms, shouldn't make the test ineffective, and should be very simple. Ideally it would help other OSes as well.
I'll close the issue—remove it from CPython's TODO list. We can reopen if you send a PR.
1 remaining item