Title: Drop use of pytz · Issue #73 · googleapis/python-api-core · GitHub
Open Graph Title: Drop use of pytz · Issue #73 · googleapis/python-api-core
X Title: Drop use of pytz · Issue #73 · googleapis/python-api-core
Description: 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. Sinc...
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/googleapis/python-api-core/issues/73
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Drop use of pytz","articleBody":"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.\r\n\r\nSince `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.\r\n\r\nIf 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`.\r\n\r\nThe 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](https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html), and other `tzinfo` providers don't have the same API. This would only happen if someone is doing something like this:\r\n\r\n```python\r\nstamp = datetime_helpers.DatetimeWithNanoseconds.from_rfc3339(\"2016-12-20T21:13:47.123456789Z\")\r\ndt = stamp.tzinfo.localize(datetime(2020, 1, 1))\r\n```\r\n\r\nIt seems unlikely that anyone is counting on this, and it's easy enough to fix if they are, particularly for UTC objects.\r\n\r\nIf you are very worried about it, I have a [`pytz-deprecation-shim`](https://pytz-deprecation-shim.readthedocs.io/en/latest/) 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).\r\n\r\nCC: @geofft","author":{"url":"https://github.com/pganssle","@type":"Person","name":"pganssle"},"datePublished":"2020-08-19T18:03:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/73/python-api-core/issues/73"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d5715d8a-9108-8bde-3f3f-571a6c9053ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B04A:100AB9:F2F768:14E64DD:6A4DD5D2 |
| html-safe-nonce | e1cc4acc70630dff986e4cb788f2d8d30bf0a6cf040c888a17ca39b599a2fa2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDRBOjEwMEFCOTpGMkY3Njg6MTRFNjRERDo2QTRERDVEMiIsInZpc2l0b3JfaWQiOiI2MTk5MzI5Mzg3MDc1OTgyODAyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1172ae89e594da1e75822b4a98103a7bc14fad8f7b235c764636daebe5560717 |
| hovercard-subject-tag | issue:682033704 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-api-core/73/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0ef9920097898c2a475ea84510ff74077c1b409974d6be06960ad534c9c24f10/googleapis/python-api-core/issues/73 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0ef9920097898c2a475ea84510ff74077c1b409974d6be06960ad534c9c24f10/googleapis/python-api-core/issues/73 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pganssle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-api-core git https://github.com/googleapis/python-api-core.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992456 |
| octolytics-dimension-repository_nwo | googleapis/python-api-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992456 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-api-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width