Title: datetime: strftime method takes different keyword argument: fmt (pure) or format (C)
Type: behavior Stage: patch review
Components: Extension Modules, Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, ZackerySpytz, belopolsky, p-ganssle
Priority: normal Keywords: patch

Created on 2020-07-09 17:01 by Anthony Sottile, last changed 2020-08-03 05:50 by ZackerySpytz.

Pull Requests
URL Status Linked Edit
PR 21712 open ZackerySpytz, 2020-08-03 05:50
Messages (3)
msg373407 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-07-09 17:01

pure python:

this makes it difficult to properly type in mypy:

and calling with `.strftime(fmt=...)` or `.strftime(format=...)` is inconsistent

(that said, it should _probably_ be a positional-only argument)
msg373421 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2020-07-09 19:06
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:

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).
msg373424 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-07-09 19:42
awesome, I'm going to work through this with someone in my discord as a demo / mentorship opportunity -- hope that's ok!
Date User Action Args
2020-08-03 05:50:20ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request20856
stage: needs patch -> patch review
2020-07-09 19:42:04Anthony Sottilesetmessages: + msg373424
2020-07-09 19:06:30p-gansslesetnosy: - rkm

messages: + msg373421
stage: needs patch
2020-07-09 18:44:02rkmsetnosy: + rkm
2020-07-09 17:52:08xtreaksetnosy: + belopolsky, p-ganssle
2020-07-09 17:01:48Anthony Sottilecreate