Skip to content

Commit 1e89eed

Browse files
authored
Remove pytz and replace usage with core python modules (#80)
Pytz is deprecated since Python 3.9. You might want to keep it for backwards compatibility for Python 3.8. However, turning naive datetimes into UTC timezone datetimes seems also possible in Python 3.8 without using the pytc library.
1 parent 0ebc397 commit 1e89eed

File tree

4 files changed

+5
-30
lines changed

4 files changed

+5
-30
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
- id: mypy
66
args: [--strict]
77
additional_dependencies:
8-
[pydantic, pytest, pytest_mock, types-requests, flagsmith-flag-engine, responses, types-pytz, sseclient-py]
8+
[pydantic, pytest, pytest_mock, types-requests, flagsmith-flag-engine, responses, sseclient-py]
99
- repo: https://github.com/PyCQA/isort
1010
rev: 5.12.0
1111
hooks:

flagsmith/flagsmith.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import json
22
import logging
33
import typing
4-
from datetime import datetime
4+
from datetime import datetime, timezone
55

6-
import pytz
76
import requests
87
from flag_engine import engine
98
from flag_engine.environments.models import EnvironmentModel
@@ -212,15 +211,15 @@ def handle_stream_event(self, event: StreamEvent) -> None:
212211
) from e
213212

214213
if stream_updated_at.tzinfo is None:
215-
stream_updated_at = pytz.utc.localize(stream_updated_at)
214+
stream_updated_at = stream_updated_at.astimezone(timezone.utc)
216215

217216
if not self._environment:
218217
raise ValueError(
219218
"Unable to access environment. Environment should not be null"
220219
)
221220
environment_updated_at = self._environment.updated_at
222221
if environment_updated_at.tzinfo is None:
223-
environment_updated_at = pytz.utc.localize(environment_updated_at)
222+
environment_updated_at = environment_updated_at.astimezone(timezone.utc)
224223

225224
if stream_updated_at > environment_updated_at:
226225
self.update_environment()

poetry.lock

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ requests = "^2.27.1"
1515
requests-futures = "^1.0.0"
1616
flagsmith-flag-engine = "^5.1.0"
1717
sseclient-py = "^1.8.0"
18-
pytz = "^2023.4"
1918

2019
[tool.poetry.group.dev]
2120
optional = true
@@ -31,7 +30,6 @@ isort = "^5.12.0"
3130
mypy = "^1.7.1"
3231
types-requests = "^2.31.0.10"
3332
pytest-cov = "^4.1.0"
34-
types-pytz = "^2024.1.0.20240203"
3533

3634
[tool.mypy]
3735
plugins = ["pydantic.mypy"]

0 commit comments

Comments
 (0)