Skip to content

Replace deprecated utcnow() with now(UTC) #1097

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

Merged
merged 2 commits into from
May 17, 2023

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented May 16, 2023

datetime.datetime.utcnow raises a deprecation warning in Python 3.12: python/cpython#103857.

datetime.UTC is new in 3.11, and is an alias of datetime.timezone.utc, but I think we're fine requiring 3.11+ here.

https://docs.python.org/3/library/datetime.html#datetime.UTC


📚 Documentation preview 📚: https://cpython-devguide--1097.org.readthedocs.build/

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Mariatta
Copy link
Member

Should we mention on the readme that things should be run using Python 3.11?

@hugovk
Copy link
Member Author

hugovk commented May 16, 2023

Good idea! I removed the bit about a Python needing venv, because venv was added in 3.3 :)

@hugovk hugovk merged commit bb85592 into python:main May 17, 2023
@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jun 3, 2023

I was taking a break at the time due to PyCon, sorry, but I'm afraid I don't really understand the rationale for requiring the latest upstream Python version released only a few months ago to be able to render the devguide locally. Sure, many folks will have it one way or another, but it's far from a given as it targets contributors of all experience levels (especially newer ones) and those that make non-code contributions, and if they're using the make workflow they will likely need to figure out how to set the right version manually.

By contrast to how much this is likely to make life harder for many contributors, especially newer ones, it seems easy to avoid this minor issue (a mere warning) all in one line by, e.g., using a ternary conditional:

now_str = str(dt.datetime.now(dt.UTC) if sys.version_info > (3, 10) else dt.datetime.utcnow())

Is there something I'm missing here?

@hugovk hugovk deleted the replace-deprecated-utcnow branch June 3, 2023 07:07
@hugovk
Copy link
Member Author

hugovk commented Jun 3, 2023

Sure, please see PR #1107.

@CAM-Gerlach
Copy link
Member

Thanks @hugovk , as always!

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.

None yet

4 participants