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

RFE: use zoneinfo instead of pytz #56

Closed
kloczek opened this issue May 28, 2024 · 11 comments · Fixed by #65
Closed

RFE: use zoneinfo instead of pytz #56

kloczek opened this issue May 28, 2024 · 11 comments · Fixed by #65

Comments

@kloczek
Copy link

kloczek commented May 28, 2024

Switch to standard zoneinfo module.
Below may help pydantic/pydantic-core@fd262933

@rbtcollins
Copy link
Member

Whats the motivation?

@cjwatson
Copy link
Contributor

I think there's something to be said for avoiding non-stdlib dependencies when they're not needed. pytz used to be one of the easiest ways to get hold of a timezone object, but that hasn't been the case for a while now.

That said, I don't know why this package would use zoneinfo, since (unlike pydantic-core) it only uses pytz.UTC. datetime.timezone.utc is simpler and should be good enough.

@rbtcollins
Copy link
Member

zoneinfo was introduced in 3.11; 3.8 is still receiving security fixes; I'm not super keen with Python with depending on the latest and greatest - have had significant pain with slow upgraders in the past.

https://docs.python.org/3/library/datetime.html#datetime.timezone.utc sadly doesn't list when it was added; possibly 3.2.

@cjwatson
Copy link
Contributor

cjwatson commented Jul 21, 2024

datetime.timezone.utc was indeed added in Python 3.2. That would require testrepository dropping support for Python 2 (which I assume only hasn't been done because nobody has got round to it yet, but can you confirm that?).

@rbtcollins
Copy link
Member

I think its dropped in every way that matters. We can remove the classifier as well of course.

@kloczek
Copy link
Author

kloczek commented Jul 22, 2024

Additionally zoneinfo has been introduced in python 3.9 https://docs.python.org/3/library/zoneinfo.html
Python 3.8 will be EOSed in few weeks (Oct this year).

@cjwatson
Copy link
Contributor

This is true, but it's moot since there's absolutely no point in using zoneinfo for UTC. It's only needed when you need other timezones from the IANA database.

@kloczek
Copy link
Author

kloczek commented Jul 22, 2024

Both modules ze in standard OOTB set.
If you have any idea how to measure reading UTC time over zoneinfo or datetime metrics values taken from such reads should be used to make final decision.

@cjwatson
Copy link
Contributor

Even the zoneinfo docs mention using timezone.utc for the UTC case.

@cjwatson
Copy link
Contributor

#64 drops Python 2 support. If that looks good then we can take advantage of py3-specific timezone handling after that.

@rbtcollins
Copy link
Member

Sorry, I misspoke before about introduction time. I meant datetime.UTC - which was added in 3.11 -

datetime.UTC

    Alias for the UTC time zone singleton [datetime.timezone.utc](https://docs.python.org/3/library/datetime.html#datetime.timezone.utc).

    Added in version 3.11.

I've merged #64, and will happily merge a change that uses datetime.timezone.utc.

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 a pull request may close this issue.

3 participants