classification
Title: '%Z' strftime specifier never works with musl
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, benjamin.peterson, p-ganssle, xiang.zhang
Priority: normal Keywords: patch

Created on 2018-09-14 04:01 by benjamin.peterson, last changed 2018-10-29 16:49 by belopolsky.

Pull Requests
URL Status Linked Edit
PR 9288 merged benjamin.peterson, 2018-09-14 04:06
PR 9312 merged benjamin.peterson, 2018-09-14 17:04
PR 10176 merged xiang.zhang, 2018-10-28 15:32
Messages (5)
msg325319 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 04:01
With the musl C library, one has failures like this:

======================================================================
FAIL: test_strptime (test.test_time.TimeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-alpine/build/Lib/test/test_time.py", line 273, in test_strptime
    time.strptime(strf_output, format)
ValueError: time data '' does not match format '%Z'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-alpine/build/Lib/test/test_time.py", line 276, in test_strptime
    (format, strf_output))
AssertionError: conversion specifier '%Z' failed with '' input.
----------------------------------------------------------------------

The root problem is that time.strptime('%Z', time.gmtime()) won't work—it returns an empty string—even though time.gmtime() will probably have a valid tm_zone field. This is because musl has a safety mechanism where it refuses to process a tm_zone entry unless it produced the string. (See https://git.musl-libc.org/cgit/musl/commit/?id=d78be392e144c338f58ce6a51d82c859126c137d.)

As a partial workaround, I propose we check whether an incoming time.struct_time instance has an tm_zone member equal to tzname[0] or tzname[1], and place one of those global strings into the C-level tm struct if they do match.
msg325357 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 16:09
New changeset 5633c4f342d957df2ef0d67b9bfb472a0d28a76b by Benjamin Peterson in branch 'master':
bpo-34672: Try to pass the C library's own timezone strings back to it. (GH-9288)
https://github.com/python/cpython/commit/5633c4f342d957df2ef0d67b9bfb472a0d28a76b
msg325368 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 17:39
New changeset b93062b7fbc965cd0d522f597ed51eb4e493dfc2 by Benjamin Peterson in branch 'master':
bpo-34672: Don't pass NULL to gmtime_r. (GH-9312)
https://github.com/python/cpython/commit/b93062b7fbc965cd0d522f597ed51eb4e493dfc2
msg328695 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2018-10-28 15:58
New changeset 163eca34c48f1b25e1504e37f4656773fd0fdc78 by Xiang Zhang in branch 'master':
bpo-34672: fix a compiler warning in timemodule.c (GH-10176)
https://github.com/python/cpython/commit/163eca34c48f1b25e1504e37f4656773fd0fdc78
msg328841 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2018-10-29 16:49
It looks like this issue has been fixed by GH-9288.  Can this be closed?  Should we backport?
History
Date User Action Args
2018-10-29 16:49:09belopolskysetmessages: + msg328841
2018-10-28 15:58:46xiang.zhangsetnosy: + xiang.zhang
messages: + msg328695
2018-10-28 15:32:55xiang.zhangsetpull_requests: + pull_request9499
2018-09-14 23:47:23p-gansslesetnosy: + belopolsky
2018-09-14 17:39:16benjamin.petersonsetmessages: + msg325368
2018-09-14 17:04:31benjamin.petersonsetpull_requests: + pull_request8738
2018-09-14 16:21:53p-gansslesetnosy: + p-ganssle
2018-09-14 16:09:08benjamin.petersonsetmessages: + msg325357
2018-09-14 04:06:29benjamin.petersonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8719
2018-09-14 04:01:29benjamin.petersoncreate