8000 chore: Drop dependency on `pytz` by using stdlib `datetime.timezone.u… · Siris4/twilio-python@c18ba65 · GitHub
[go: up one dir, main page]

Skip to content

Commit c18ba65

Browse files
Zac-HDAsabuHere
andauthored
chore: Drop dependency on pytz by using stdlib datetime.timezone.utc (twilio#721)
* Fix type hints for non-None return * Use stdlib instead of pytz.utc --------- Co-authored-by: Athira Sabu <102021496+AsabuHere@users.noreply.github.com>
1 parent 6d30502 commit c18ba65

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pygments>=2.7.4 # not directly required, pinned by Snyk to avoid a vulnerability
2-
pytz
32
requests>=2.0.0
43
PyJWT>=2.0.0, <3.0.0
54
aiohttp>=3.8.4

setup.py

100755100644
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
keywords=["twilio", "twiml"],
2222
python_requires=">=3.7.0",
2323
install_requires=[
24-
"pytz",
2524
"requests >= 2.0.0",
2625
"PyJWT >= 2.0.0, < 3.0.0",
2726
"aiohttp>=3.8.4",

tests/unit/base/test_deserialize.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import unittest
33
from decimal import Decimal
44

5-
import pytz
6-
75
from twilio.base import deserialize
86

97

@@ -21,7 +19,7 @@ def test_not_parsable(self):
2119
class Iso8601DateTimeTestCase(unittest.TestCase):
2220
def test_parsable(self):
2321
actual = deserialize.iso8601_datetime("2015-01-02T03:04:05Z")
24-
expected = datetime.datetime(2015, 1, 2, 3, 4, 5, 0, pytz.utc)
22+
expected = datetime.datetime(2015, 1, 2, 3, 4, 5, 0, datetime.timezone.utc)
2523
self.assertEqual(expected, actual)
2624

2725
def test_not_parsable(self):

twilio/base/deserialize.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
from email.utils import parsedate
44
from typing import Optional, Union
55

6-
import pytz
7-
86
ISO8601_DATE_FORMAT = "%Y-%m-%d"
97
ISO8601_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
108

119

12-
def iso8601_date(s: str) -> Optional[Union[datetime.date, str]]:
10+
def iso8601_date(s: str) -> Union[datetime.date, str]:
1311
"""
1412
Parses an ISO 8601 date string and returns a UTC date object or the string
1513
if the parsing failed.
@@ -19,7 +17,7 @@ def iso8601_date(s: str) -> Optional[Union[datetime.date, str]]:
1917
try:
2018
return (
2119
datetime.datetime.strptime(s, ISO8601_DATE_FORMAT)
22-
.replace(tzinfo=pytz.utc)
20+
.replace(tzinfo=datetime.timezone.utc)
2321
.date()
2422
)
2523
except (TypeError, ValueError):
@@ -28,15 +26,15 @@ def iso8601_date(s: str) -> Optional[Union[datetime.date, str]]:
2826

2927
def iso8601_datetime(
3028
s: str,
31-
) -> Optional[Union[datetime.datetime, str]]:
29+
) -> Union[datetime.datetime, str]:
3230
"""
3331
Parses an ISO 8601 datetime string and returns a UTC datetime object,
3432
or the string if parsing failed.
3533
:param s: ISO 8601-formatted datetime string (2015-01-25T12:34:56Z)
3634
"""
3735
try:
3836
return datetime.datetime.strptime(s, ISO8601_DATETIME_FORMAT).replace(
39-
tzinfo=pytz.utc
37+
tzinfo=datetime.timezone.utc
4038
)
4139
except (TypeError, ValueError):
4240
return s
@@ -52,10 +50,10 @@ def rfc2822_datetime(s: str) -> Optional[datetime.datetime]:
5250
date_tuple = parsedate(s)
5351
if date_tuple is None:
5452
return None
55-
return datetime.datetime(*date_tuple[:6]).replace(tzinfo=pytz.utc)
53+
return datetime.datetime(*date_tuple[:6]).replace(tzinfo=datetime.timezone.utc)
5654

5755

58-
def decimal(d: Optional[str]) -> Optional[Union[Decimal, str]]:
56+
def decimal(d: Optional[str]) -> Union[Decimal, str]:
5957
"""
6058
Parses a decimal string into a Decimal
6159
:param d: decimal string
@@ -65,7 +63,7 @@ def decimal(d: Optional[str]) -> Optional[Union[Decimal, str]]:
6563
return Decimal(d, BasicContext)
6664

6765

68-
def integer(i: str) -> Optional[Union[int, str]]:
66+
def integer(i: str) -> Union[int, str]:
6967
"""
7068
Parses an integer string into an int
7169
:param i: integer string

0 commit comments

Comments
 (0)
0