bpo-40799: Add _pydatetime module (Python datetime impl)#20472
bpo-40799: Add _pydatetime module (Python datetime impl)#20472vstinner wants to merge 3 commits into
Conversation
|
@pganssle: This change makes "import decimal" 4.31x faster (814 us +- 32 us -> 189 us +- 4 us). In https://bugs.python.org/issue40799 you discussed the idea of converting datetime into a package. I'm not convinced by this idea, but I'm open for discussion :-) What do you think of this change? Is it to merge it? |
Sorry, something went wrong.
|
This PR reduce names exposed in dir(datetime). I just updated my PR to remove datetime.sys when the pure Python implementation is used. The C implementation exposes datetime.datetime_CAPI capsule. Maybe it can be removed, but it should be done in a separated change. Before: After:
|
Sorry, something went wrong.
|
@pganssle: I plan to merge this PR next Monday. It makes "import datetime" 4.3x faster by avoiding importing time, math, sys and operator modules (when the C extension is available). This PR doesn't prevent to convert datetime.py into a package later. Well, see https://bugs.python.org/issue40799 for the rationale ;-) |
Sorry, something went wrong.
|
Ah, and this PR also fix https://bugs.python.org/issue40058 bug. |
Sorry, something went wrong.
|
Please don't merge this next Monday without review. |
Sorry, something went wrong.
I pinged you 2 weeks ago and you didn't reply. Great if you can review it :-) |
Sorry, something went wrong.
Yes, my review queue is very long and I don't have a lot of time to clear it out. I think this is an important change and probably a good idea, but it's also a major change, one that, AFAICT, will break all automatic backporting for Also:
It's true that it doesn't, but unless I'm mistaken, that will be another event that breaks backporting and makes it more complicated to navigate the project history. I'm not saying that these are show-stoppers, but given that |
Sorry, something went wrong.
I tried to make a dummy change on top on my PR: a cherry-pick to 3.9 of this change without the rename change failed. I rewrote this PR differently, and I ran the same test: the cherry-pick worked this time! Maybe it's because this PR not only rename datetime.py, it also makes multiple changes _pydatetime.py at the same time. |
Sorry, something went wrong.
|
Hum, it seems like depending on the number of changes in _pydatetime.py, git cherry-pick manages to detect the rename or not. |
Sorry, something went wrong.
|
Between datetime.py file for datetime package (Lib/datetime/init.py), I have no preference. It seems like both options solve https://bugs.python.org/issue40799. But I have concerns about moving Lib/_strptime.py into the package. See https://bugs.python.org/issue40799. Maybe _strptime.py can be move once these concerns are answered/fixed. |
Sorry, something went wrong.
Good to know. If we can do this in a way that cherry-pick continues to work, I'd be a lot happier merging it as early in the cycle as possible. I'm going to comment on the |
Sorry, something went wrong.
Sure, me too :-) |
Sorry, something went wrong.
|
I like this change, thanks for the work!!! The conversation in python-dev ended in agreement with this change (overe having a package), so it looks we're green to go. @vstinner one detail, though, shouldn't we keep the |
Sorry, something went wrong.
Move the Python implementation of the datetime module into a new Lib/_pydatetime.py file to optimize "import datetime". * Define datetime.__all__ in Lib/datetime.py. * _pydatetime.py defines __name__ as 'datetime' for pickle. * TestModule.test_divide_and_round() now imports directly _pydatetime, since _divide_and_round() is no longer exported by the datetime module. * test_datetime also requires a fresh _pydatetime when loading pure_tests.
|
I rebased the PR. |
Sorry, something went wrong.
I don't understand your question. Would you mind to elaborate? _pydatetime.py contains: |
Sorry, something went wrong.
|
I'm not sure that git blame and git cherry-pick will work once the 3 commits of this PR will be squashed into a single commit. Maybe I will need a GitHub admin to allow me to merge without squashing, only for this PR, to help Git to detect that the file is renamed. |
Sorry, something went wrong.
facundobatista
left a comment
There was a problem hiding this comment.
Great work, thanks!
Sorry, something went wrong.
I was on the impression that it needed to be in the "main .py" file, that somehow the "from ... import *" didn't apply to FTR, decimal (and it's dependant python/C implementations) follow the same patter here, so I deduce it's ok. Thanks! again! |
Sorry, something went wrong.
pganssle
left a comment
There was a problem hiding this comment.
LGTM, except for one change to the tests. Sorry for the long delay here.
I think maybe @pablogsal has permissions to do a rebase-merge or standard merge (to preserve the ability to do backports). Ideally we'd test this on some random branch using miss-islington if that can be arranged (though I'm not sure how easy that would be).
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
|
I lost track of this PR and it's now outdated (in conflict). I close it. A new PR should be created. |
Sorry, something went wrong.
Move the Python implementation of the datetime module into a new
Lib/_pydatetime.py file to optimize "import datetime".
_pydatetime, since _divide_and_round() is no longer exported by the
datetime module.
pure_tests.
https://bugs.python.org/issue40799