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, date and time: strftime method takes different keyword argument: fmt (pure) or format (C) #85432
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-07-09.17:01:48.789>labels= ['type-bug', '3.9', '3.10', '3.11', 'extension-modules', 'library']
title='datetime, date and time: strftime method takes different keyword argument: fmt (pure) or format (C)'updated_at=<Date2021-11-16.19:27:41.778>user='https://github.com/asottile'
I think a positional-only argument would be the best option if we could do it, but it would be a backwards-incompatible change and it's probably not worth the hassle.
If anyone is using the keyword argument, they're probably using format= rather than fmt=, since it's pretty rare for anyone to use the pure python version of datetime. PyPy uses it, but I think they tend to aim for consistency with the C API of CPython, and it seems like they already patch s/fmt/format/ themselves: https://foss.heptapod.net/pypy/pypy/-/blob/branch/default/lib_pypy/datetime.py#L781
If anyone wants to make a PR I think we can fix this for 3.10, though unfortunately because it is an API change it can't be backported. I think in typeshed they can safely change from fmt to format even today (which would almost certainly be more accurate to end user use cases).
asottile commented on Jul 9, 2020
asottilemannequin
MannequinAuthor
More actions
awesome, I'm going to work through this with someone in my discord as a demo / mentorship opportunity -- hope that's ok!
changed the title [-]datetime: strftime method takes different keyword argument: fmt (pure) or format (C)[/-][+]datetime, date and time: strftime method takes different keyword argument: fmt (pure) or format (C)[/+]on Nov 16, 2021
changed the title [-]datetime: strftime method takes different keyword argument: fmt (pure) or format (C)[/-][+]datetime, date and time: strftime method takes different keyword argument: fmt (pure) or format (C)[/+]on Nov 16, 2021
In addition to date.strftime and time.strftime, there is also a discrepancy in datetime.fromtimestamp. In the C implementation, the first parameter is called "timestamp"; in the pure-Python implementation, the first parameter is called "t".
Activity
asottile commentedon Jul 9, 2020
C:
cpython/Modules/_datetimemodule.c
Line 3183 in 8b33961
pure python:
cpython/Lib/datetime.py
Line 927 in 8b33961
this makes it difficult to properly type in mypy:
https://github.com/python/typeshed/blob/209b6bb127f61fe173a60776e23883ac450cf1c8/stdlib/2and3/datetime.pyi#L55
and calling with
.strftime(fmt=...)or.strftime(format=...)is inconsistent(that said, it should _probably_ be a positional-only argument)
pganssle commentedon Jul 9, 2020
I think a positional-only argument would be the best option if we could do it, but it would be a backwards-incompatible change and it's probably not worth the hassle.
If anyone is using the keyword argument, they're probably using
format=rather thanfmt=, since it's pretty rare for anyone to use the pure python version of datetime. PyPy uses it, but I think they tend to aim for consistency with the C API of CPython, and it seems like they already patch s/fmt/format/ themselves: https://foss.heptapod.net/pypy/pypy/-/blob/branch/default/lib_pypy/datetime.py#L781If anyone wants to make a PR I think we can fix this for 3.10, though unfortunately because it is an API change it can't be backported. I think in typeshed they can safely change from
fmttoformateven today (which would almost certainly be more accurate to end user use cases).asottile commentedon Jul 9, 2020
awesome, I'm going to work through this with someone in my discord as a demo / mentorship opportunity -- hope that's ok!
pganssle commentedon Nov 16, 2021
Updating this issue to cover the problem in date, time and datetime.
[-]datetime: strftime method takes different keyword argument: fmt (pure) or format (C)[/-][+]datetime, date and time: strftime method takes different keyword argument: fmt (pure) or format (C)[/+][-]datetime: strftime method takes different keyword argument: fmt (pure) or format (C)[/-][+]datetime, date and time: strftime method takes different keyword argument: fmt (pure) or format (C)[/+]srittau commentedon Nov 16, 2021
Ref python/typeshed#6317 for a discussion about this in typeshed.
AlexWaygood commentedon Nov 16, 2021
In addition to
date.strftimeandtime.strftime, there is also a discrepancy indatetime.fromtimestamp. In the C implementation, the first parameter is called "timestamp"; in the pure-Python implementation, the first parameter is called "t".pythongh-85432: harmonise parameter names between C and pure-Python i…
pythongh-85432: harmonise parameter names between C and pure-Python i…
gh-85432: Harmonise parameter names between C and pure-Python impleme…
Merged main into regmachine branch (#50)