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

Drop use of pytz #73

Closed
pganssle opened this issue Aug 19, 2020 · 1 comment
Closed

Drop use of pytz #73

pganssle opened this issue Aug 19, 2020 · 1 comment
Labels
type: cleanup An internal cleanup or hygiene concern.

Comments

@pganssle
Copy link

pganssle commented Aug 19, 2020

From what I can tell, pytz is only used to access a UTC time zone, and to create fixed offsets in the tests. Both of these use cases are supported in the Python standard library datetime module in all supported versions of Python 3.

Since pytz is deprecated or semi-deprecated, it would be a good idea to remove the pytz dependency as soon as possible. It seems that the master branch has not dropped Python 2.7 support yet, so I think the prudent course of action would be to either drop Python 2.7 support entirely in the next release, and drop the pytz dependency along with it.

If you cannot drop Python 2.7 support, it's fairly trivial to write a UTC object for Python 2.7 compatibility, or you can add a 2.7-only dependency on python-dateutil to get access to dateutil.tz.UTC and dateutil.tz.tzoffset.

The only downside to dropping pytz is that if a user is counting on your methods generating datetime objects with pytz.UTC attached, because they are doing something like dt.tzinfo.localize(something). This is because pytz has its own non-standard time zone interface, and other tzinfo providers don't have the same API. This would only happen if someone is doing something like this:

stamp = datetime_helpers.DatetimeWithNanoseconds.from_rfc3339("2016-12-20T21:13:47.123456789Z")
dt = stamp.tzinfo.localize(datetime(2020, 1, 1))

It seems unlikely that anyone is counting on this, and it's easy enough to fix if they are, particularly for UTC objects.

If you are very worried about it, I have a pytz-deprecation-shim module that provides the same API as pytz, but can be used as a normal tzinfo, and raises deprecation warnings whenever the pytz-specific methods are used. I believe that is probably a heavier dependency than you need for these purposes (it also works in Python 2.7).

CC: @geofft

@tseaver
Copy link
Contributor

tseaver commented Sep 27, 2021

Via #212.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants