bpo-32497: let datetime.strptime interpret tzname#5106
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
|
@akeeman I'll note that your example uses |
|
Tests go in Lib/test/datetimetester.py. |
|
It seems that this pull request might be abandoned. @pganssle, is this change something you think should be pursued in light of the other time zone changes you have planned? Thanks! |
|
@csabella The new time zone support doesn't really change things, because the stuff you would parse with I went into considerably more detail on the bpo issue about the possible options for this interface. I don't particularly like the one that @akeeman has chosen, but it's close enough to one that I'd accept as a compromise 😉. If this or any other PR were to succeed, though, it would need:
That said, regardless of any criticisms I have about the interface, I appreciate that @akeeman took the time to bring up this issue and to take an initial crack at the implementation, so thank you Arjan! |
|
@pganssle, thank you for your response. @akeeman, please let us know if you are interested in pursuing this pull request by applying the changes that Paul requested and by rebasing to resolve the merge conflicts. If you are no longer interested in this, then I'll close the PR to allow someone else to attempt it. Thanks! |
|
@pganssle Thanks for the comment. I hope that there are better ways to do it too, but mostly wanted to start a discussion and have some ideas going. I'll read your linked issue soon. I'd like the best implementation, and that doesn't necessarily have to be this one. (@csabella "[...] then I'll close the PR to allow someone else to attempt it." -> if someone has interest to do it, you can make an attempt right now if you ask me. Don't hesitate to move this pr aside if there's a better one.) As for this pr; The given points are clearly valid, and should be implemented. I'll try to make some time soon. |
|
After reading the bpo issue, can I say that you, @pganssle, would like to see the arg I've called |
|
Changed things to where (I still have to add tests) |
Consider the following:
Python's standard library is not capable of converting the timezone name CET to a tzinfo object. Therefore the case made above returns a timezone naive datetime object.
I propose to add an extra optional argument to
_strptime.py's_strptime_datetimefunction, and todatetime.strptime:infos:Union[None, Mapping, Callable[[datetime, str],Optional[tzinfo]]]=None. This parameter can be set with a function that accepts the timezone name and returns a tzinfo object or None. None will mean that a timezone naive object will be created.Usage:
Note that I did not found the location to add tests yet. Can someone point it out to me?
https://bugs.python.org/issue32497