Skip to content

Commit 317b4b7

Browse files
WeepingClown13Ananthu C V
andauthored
remove dependency on pytz (#911)
Co-authored-by: Ananthu C V <[email protected]>
1 parent 8a1860d commit 317b4b7

File tree

7 files changed

+39
-64
lines changed

7 files changed

+39
-64
lines changed

docs/docs/duration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ It has many improvements over the base class.
1111

1212
```python
1313
>>> import pendulum
14-
>>> from datetime import datetime
14+
>>> import datetime
1515

16-
>>> d1 = datetime(2012, 1, 1, 1, 2, 3, tzinfo=pytz.UTC)
17-
>>> d2 = datetime(2011, 12, 31, 22, 2, 3, tzinfo=pytz.UTC)
16+
>>> d1 = datetime.datetime(2012, 1, 1, 1, 2, 3, tzinfo=datetime.UTC)
17+
>>> d2 = datetime.datetime(2011, 12, 31, 22, 2, 3, tzinfo=datetime.UTC)
1818
>>> delta = d2 - d1
1919
>>> delta.days
2020
-1

poetry.lock

Lines changed: 11 additions & 35 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
@@ -35,7 +35,6 @@ Repository = "https://github.com/sdispater/pendulum"
3535

3636
[tool.poetry.group.test.dependencies]
3737
pytest = "^7.1.2"
38-
pytz = ">=2022.1"
3938
time-machine = ">=2.16.0"
4039
pytest-benchmark = "^4.0.0"
4140

@@ -51,7 +50,6 @@ pre-commit = "^3.0.0"
5150
[tool.poetry.group.typing.dependencies]
5251
mypy = "^1.3.0"
5352
types-python-dateutil = "^2.8.19"
54-
types-pytz = ">=2022.7.1.2"
5553

5654
[tool.poetry.group.dev.dependencies]
5755
babel = "^2.10.3"

tests/datetime/test_comparison.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3-
from datetime import datetime
3+
import zoneinfo
44

5-
import pytz
5+
from datetime import datetime
66

77
import pendulum
88

@@ -99,7 +99,7 @@ def test_greater_than_false():
9999
def test_greater_than_with_timezone_true():
100100
d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
101101
d2 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver")
102-
d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 8, 59, 59))
102+
d3 = datetime(2000, 1, 1, 8, 59, 59, tzinfo=zoneinfo.ZoneInfo("America/Vancouver"))
103103

104104
assert d1 > d2
105105
assert d1 > d3
@@ -108,7 +108,7 @@ def test_greater_than_with_timezone_true():
108108
def test_greater_than_with_timezone_false():
109109
d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
110110
d2 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver")
111-
d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 9, 0, 1))
111+
d3 = datetime(2000, 1, 1, 9, 0, 1, tzinfo=zoneinfo.ZoneInfo("America/Vancouver"))
112112

113113
assert not d1 > d2
114114
assert not d1 > d3
@@ -144,7 +144,7 @@ def test_greater_than_or_equal_false():
144144
def test_greater_than_or_equal_with_timezone_true():
145145
d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
146146
d2 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver")
147-
d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 8, 59, 59))
147+
d3 = datetime(2000, 1, 1, 8, 59, 59, tzinfo=zoneinfo.ZoneInfo("America/Vancouver"))
148148

149149
assert d1 >= d2
150150
assert d1 >= d3
@@ -153,7 +153,7 @@ def test_greater_than_or_equal_with_timezone_true():
153153
def test_greater_than_or_equal_with_timezone_false():
154154
d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
155155
d2 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver")
156-
d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 9, 0, 1))
156+
d3 = datetime(2000, 1, 1, 9, 0, 1, tzinfo=zoneinfo.ZoneInfo("America/Vancouver"))
157157

158158
assert not d1 >= d2
159159
assert not d1 >= d3
@@ -180,7 +180,7 @@ def test_less_than_false():
180180
def test_less_than_with_timezone_true():
181181
d1 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver")
182182
d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
183-
d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0))
183+
d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto"))
184184

185185
assert d1 < d2
186186
assert d1 < d3
@@ -189,7 +189,7 @@ def test_less_than_with_timezone_true():
189189
def test_less_than_with_timezone_false():
190190
d1 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver")
191191
d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
192-
d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0))
192+
d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto"))
193193

194194
assert not d1 < d2
195195
assert not d1 < d3
@@ -225,7 +225,7 @@ def test_less_than_or_equal_false():
225225
def test_less_than_or_equal_with_timezone_true():
226226
d1 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver")
227227
d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
228-
d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0))
228+
d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto"))
229229

230230
assert d1 <= d2
231231
assert d1 <= d3
@@ -234,7 +234,7 @@ def test_less_than_or_equal_with_timezone_true():
234234
def test_less_than_or_equal_with_timezone_false():
235235
d1 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver")
236236
d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
237-
d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0))
237+
d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto"))
238238

239239
assert not d1 <= d2
240240
assert not d1 <= d3

tests/test_helpers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

3+
import zoneinfo
4+
35
from datetime import datetime
46

57
import pytest
6-
import pytz
78

89
import pendulum
910

@@ -102,18 +103,17 @@ def test_precise_diff_timezone() -> None:
102103
assert_diff(diff, days=1, hours=5)
103104
assert diff.total_days == 1
104105

105-
# pytz
106-
paris_pytz = pytz.timezone("Europe/Paris")
107-
toronto_pytz = pytz.timezone("America/Toronto")
106+
paris_tz = zoneinfo.ZoneInfo("Europe/Paris")
107+
toronto_tz = zoneinfo.ZoneInfo("America/Toronto")
108108

109-
dt1 = paris_pytz.localize(datetime(2013, 3, 31, 1, 30))
110-
dt2 = paris_pytz.localize(datetime(2013, 4, 1, 1, 30))
109+
dt1 = datetime(2013, 3, 31, 1, 30, tzinfo=paris_tz)
110+
dt2 = datetime(2013, 4, 1, 1, 30, tzinfo=paris_tz)
111111

112112
diff = precise_diff(dt1, dt2)
113113
assert_diff(diff, days=1, hours=0)
114114
assert diff.total_days == 1
115115

116-
dt2 = toronto_pytz.localize(datetime(2013, 4, 1, 1, 30))
116+
dt2 = datetime(2013, 4, 1, 1, 30, tzinfo=toronto_tz)
117117

118118
diff = precise_diff(dt1, dt2)
119119
assert_diff(diff, days=1, hours=5)

tests/test_main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

3+
import zoneinfo
4+
35
from datetime import date
46
from datetime import datetime
57
from datetime import time
68

7-
import pytz
8-
99
from dateutil import tz
1010

1111
import pendulum
@@ -25,8 +25,8 @@ def test_instance_with_aware_datetime() -> None:
2525
assert now.timezone_name == "Europe/Paris"
2626

2727

28-
def test_instance_with_aware_datetime_pytz() -> None:
29-
now = pendulum.instance(datetime.now(pytz.timezone("Europe/Paris")))
28+
def test_instance_with_aware_datetime_zoneinfo() -> None:
29+
now = pendulum.instance(datetime.now(zoneinfo.ZoneInfo("Europe/Paris")))
3030
assert now.timezone_name == "Europe/Paris"
3131

3232

@@ -57,7 +57,7 @@ def test_instance_with_aware_time() -> None:
5757

5858

5959
def test_safe_timezone_with_tzinfo_objects() -> None:
60-
tz = _safe_timezone(pytz.timezone("Europe/Paris"))
60+
tz = _safe_timezone(zoneinfo.ZoneInfo("Europe/Paris"))
6161

6262
assert isinstance(tz, Timezone)
6363
assert tz.name == "Europe/Paris"

tests/time/test_sub.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
import zoneinfo
4+
35
from datetime import time
46
from datetime import timedelta
57

68
import pytest
7-
import pytz
89

910
import pendulum
1011

@@ -87,7 +88,7 @@ def test_subtract_time():
8788
t = Time(12, 34, 56)
8889
t1 = Time(1, 1, 1)
8990
t2 = time(1, 1, 1)
90-
t3 = time(1, 1, 1, tzinfo=pytz.timezone("Europe/Paris"))
91+
t3 = time(1, 1, 1, tzinfo=zoneinfo.ZoneInfo("Europe/Paris"))
9192

9293
diff = t - t1
9394
assert isinstance(diff, pendulum.Duration)

0 commit comments

Comments
 (0)