Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace datetime.utcnow #215

Closed
wants to merge 2 commits into from
Closed

Replace datetime.utcnow #215

wants to merge 2 commits into from

Conversation

cdce8p
Copy link

@cdce8p cdce8p commented Aug 20, 2023

Starting with Python 3.12 datetime.utcnow will be deprecated.
https://docs.python.org/3.12/library/datetime.html#datetime.datetime.utcnow

@codecov
Copy link

codecov bot commented Aug 20, 2023

Codecov Report

Merging #215 (7a1d161) into main (e4857f9) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #215   +/-   ##
=======================================
  Coverage   96.76%   96.76%           
=======================================
  Files          44       44           
  Lines        2655     2655           
=======================================
  Hits         2569     2569           
  Misses         86       86           
Files Changed Coverage Δ
ical/util.py 95.65% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@allenporter
Copy link
Owner

allenporter commented Aug 20, 2023

Similar to my comment on the home assistant PR, I think its more helpful to continue to use the deprecated method given the guidance it is preferred to use aware datetimes to represent times in UTC That is, meeting the spirit of the deprecation involves stopping using TZ aware times even for UTC. I'd rather leave it to indicate there is more work to cleanup here. (This isn't scheduled for removal yet, right?)

@cdce8p
Copy link
Author

cdce8p commented Aug 20, 2023

Similar to my comment on the home assistant PR, I think its more helpful to continue to use the deprecated method given the guidance it is preferred to use aware datetimes to represent times in UTC That is, meeting the spirit of the deprecation involves stopping using TZ aware times even for UTC. I'd rather leave it to indicate there is more work to cleanup here.

🤔 I would say it depends. The main change left would be to remove replace(tzinfo=None) to use a timezone aware datetime object. However, I haven't tested if that would be a breaking change. Making the tests pass is easy 7a1d161.
Overall I would say a strict replacement still has it uses. If for nothing else than to prevent it accidentally breaking with future Python versions.

In the end adding a TODO comment is almost as useful as seeing the deprecation warning. Just with the difference that there might be so many warnings that you miss the important ones when they show up.

(This isn't scheduled for removal yet, right?)

Not yet, AFAIK

@allenporter
Copy link
Owner

Yeah, i think its a larger change -- not necessarily expecting you to make it. date-times in this library are a beast.

I think the existing use of this may result in unintended behavior -- a date without a timezone is assumed to be as floating in the local timezone. So this is actually a good thing to fix, since its not expected its actually utc.

@cdce8p
Copy link
Author

cdce8p commented Aug 20, 2023

Yeah, i think its a larger change -- not necessarily expecting you to make it. date-times in this library are a beast.

Thought that might be the case. I'm going to close this PR then.
No need to fix that right now. We can filter the warning in Home Assistant once we support Python 3.12.

@cdce8p cdce8p closed this Aug 20, 2023
@cdce8p cdce8p deleted the replace-utcnow branch August 20, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants