From 4689a7bb0328cbd359d99f6d382d084a1677d2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 18 Jan 2024 16:53:57 -0600 Subject: [PATCH] refactor: Use `datetime.timezone.utc` instead of `pytz.UTC` where possible --- .gitignore | 4 ++++ pyproject.toml | 1 - singer_sdk/_singerlib/utils.py | 8 +++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 18f01b438e..d6a92f65e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Local Poetry configuration file + +poetry.toml + # CI _changelog_fragment.md diff --git a/pyproject.toml b/pyproject.toml index 6bb31917ec..599b199a0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -214,7 +214,6 @@ fail_under = 82 [tool.mypy] exclude = "tests" files = "singer_sdk" -python_version = "3.8" warn_redundant_casts = true warn_return_any = true warn_unused_configs = true diff --git a/singer_sdk/_singerlib/utils.py b/singer_sdk/_singerlib/utils.py index c86b0f37f6..7022ee86f9 100644 --- a/singer_sdk/_singerlib/utils.py +++ b/singer_sdk/_singerlib/utils.py @@ -1,9 +1,7 @@ from __future__ import annotations import sys -from datetime import datetime, timedelta - -import pytz +from datetime import datetime, timedelta, timezone if sys.version_info < (3, 11): from backports.datetime_fromisoformat import MonkeyPatch @@ -33,9 +31,9 @@ def strptime_to_utc(dtimestr: str) -> datetime: """ d_object: datetime = datetime.fromisoformat(dtimestr) if d_object.tzinfo is None: - return d_object.replace(tzinfo=pytz.UTC) + return d_object.replace(tzinfo=timezone.utc) - return d_object.astimezone(tz=pytz.UTC) + return d_object.astimezone(tz=timezone.utc) def strftime(dtime: datetime, format_str: str = DATETIME_FMT) -> str: