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
The main reason I had for not deprecating them at the time was that .utcnow() is faster than .now(datetime.UTC), and if you are immediately converting the datetime to a string, like datetime.utcnow().isoformat(), there's no danger.
I have come around to the idea that this type of use case is not important enough to leave the attractive nuisances of utcnow() and utcfromtimestamp() in place, and we should go ahead and deprecate them.
Pitch
We should deprecate them in the documentation and also add DeprecationWarnings imploring people not to use them. I'm OK with us saying that we will remove them "at some point in the future" and not necessarily putting a deadline on it, considering how much use of utcnow() is out there.
I've gone ahead and done some benchmarks for the most common legitimate use case I've seen for utcnow and utcfromtimestamp, which is getting a naïve datetime and immediately formatting it to a string with no time zone offset. The alternatives are considerably slower, though I don't know how important that is for real life use cases:
As an example of how this changes the speed in a real-life application, here are the before and after measurements for the change to http.cookiejar.time2isoz:
I'm still more or less convinced that this is useful to do, and I'd like to see if anyone complains that it's a major problem after the deprecation before worrying about these micro-optimizations.
Activity
pganssle commentedon Apr 26, 2023
I've gone ahead and done some benchmarks for the most common legitimate use case I've seen for
utcnowandutcfromtimestamp, which is getting a naïvedatetimeand immediately formatting it to a string with no time zone offset. The alternatives are considerably slower, though I don't know how important that is for real life use cases:As an example of how this changes the speed in a real-life application, here are the before and after measurements for the change to
http.cookiejar.time2isoz:I'm still more or less convinced that this is useful to do, and I'd like to see if anyone complains that it's a major problem after the deprecation before worrying about these micro-optimizations.
GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)
pganssle commentedon Apr 27, 2023
#103858 is now merged, but we still need a What's New entry before closing this, I believe.
gh-103857: Update deprecation stacktrace to point to calling line (#1…
hugovk commentedon May 16, 2023
Please see PR #104542.
Replace deprecated utcnow() with now(utc)\n\nRaises a deprecation war…
gh-103857: Document utcnow and utcfromtimestamp deprecations in What'…
hugovk commentedon May 22, 2023
I think we're all set here! 🚀
py-mongo: updated to 4.4.1
Remove use of deprecated `datetime.datetime` methods
[REF] hr*: remove the use of utcnow
[REF] hr*: remove the use of utcnow
3 remaining items
tree-wide: replace utcnow and utcfromtimestamp (#4462)
chore: swap out deprecated datetime's utcnow and utcfromtimestamp (#1…
Replace datetime.utcnow() with datetime.now(timezone.utc)
Replace datetime.utcnow() with datetime.now(timezone.utc)
py-mongo: updated to 4.4.1
py-mongo: updated to 4.4.1
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.
Fix flaky unit tests caused by mismatched timezones.