diff --git a/docs/docs/duration.md b/docs/docs/duration.md index 0801d9ea..a657d9ae 100644 --- a/docs/docs/duration.md +++ b/docs/docs/duration.md @@ -11,10 +11,10 @@ It has many improvements over the base class. ```python >>> import pendulum - >>> from datetime import datetime + >>> import datetime - >>> d1 = datetime(2012, 1, 1, 1, 2, 3, tzinfo=pytz.UTC) - >>> d2 = datetime(2011, 12, 31, 22, 2, 3, tzinfo=pytz.UTC) + >>> d1 = datetime.datetime(2012, 1, 1, 1, 2, 3, tzinfo=datetime.UTC) + >>> d2 = datetime.datetime(2011, 12, 31, 22, 2, 3, tzinfo=datetime.UTC) >>> delta = d2 - d1 >>> delta.days -1 diff --git a/poetry.lock b/poetry.lock index ad6338e5..82f0d002 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. [[package]] name = "babel" @@ -232,7 +232,7 @@ files = [ [package.extras] docs = ["furo (>=2024.8.6)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4.1)"] testing = ["covdefaults (>=2.3)", "coverage (>=7.6.1)", "diff-cover (>=9.2)", "pytest (>=8.3.3)", "pytest-asyncio (>=0.24)", "pytest-cov (>=5)", "pytest-mock (>=3.14)", "pytest-timeout (>=2.3.1)", "virtualenv (>=20.26.4)"] -typing = ["typing-extensions (>=4.12.2)"] +typing = ["typing-extensions (>=4.12.2) ; python_version < \"3.11\""] [[package]] name = "ghp-import" @@ -274,7 +274,7 @@ description = "Read metadata from Python packages" optional = false python-versions = ">=3.8" groups = ["benchmark", "doc"] -markers = "python_version < \"3.10\"" +markers = "python_version == \"3.9\"" files = [ {file = "importlib_metadata-8.5.0-py3-none-any.whl", hash = "sha256:45e54197d28b7a7f1559e60b95e7c567032b602131fbd588f1497f47880aa68b"}, {file = "importlib_metadata-8.5.0.tar.gz", hash = "sha256:71522656f0abace1d072b9e5481a48f07c138e00f079c38c8f883823f9c26bd7"}, @@ -284,12 +284,12 @@ files = [ zipp = ">=3.20" [package.extras] -check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\""] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] enabler = ["pytest-enabler (>=2.2)"] perf = ["ipython"] -test = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6,!=8.1.*)", "pytest-perf (>=0.9.2)"] +test = ["flufl.flake8", "importlib-resources (>=1.3) ; python_version < \"3.9\"", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6,!=8.1.*)", "pytest-perf (>=0.9.2)"] type = ["pytest-mypy"] [[package]] @@ -539,7 +539,7 @@ watchdog = ">=2.0" [package.extras] i18n = ["babel (>=2.9.0)"] -min-versions = ["babel (==2.9.0)", "click (==7.0)", "colorama (==0.4)", "ghp-import (==1.0)", "importlib-metadata (==4.4)", "jinja2 (==2.11.1)", "markdown (==3.3.6)", "markupsafe (==2.0.1)", "mergedeep (==1.3.4)", "mkdocs-get-deps (==0.2.0)", "packaging (==20.5)", "pathspec (==0.11.1)", "pyyaml (==5.1)", "pyyaml-env-tag (==0.1)", "watchdog (==2.0)"] +min-versions = ["babel (==2.9.0)", "click (==7.0)", "colorama (==0.4) ; platform_system == \"Windows\"", "ghp-import (==1.0)", "importlib-metadata (==4.4) ; python_version < \"3.10\"", "jinja2 (==2.11.1)", "markdown (==3.3.6)", "markupsafe (==2.0.1)", "mergedeep (==1.3.4)", "mkdocs-get-deps (==0.2.0)", "packaging (==20.5)", "pathspec (==0.11.1)", "pyyaml (==5.1)", "pyyaml-env-tag (==0.1)", "watchdog (==2.0)"] [[package]] name = "mkdocs-get-deps" @@ -883,18 +883,6 @@ files = [ [package.dependencies] six = ">=1.5" -[[package]] -name = "pytz" -version = "2024.2" -description = "World timezone definitions, modern and historical" -optional = false -python-versions = "*" -groups = ["test"] -files = [ - {file = "pytz-2024.2-py2.py3-none-any.whl", hash = "sha256:31c7c1817eb7fae7ca4b8c7ee50c72f93aa2dd863de768e1ef4245d426aa0725"}, - {file = "pytz-2024.2.tar.gz", hash = "sha256:2aa355083c50a0f93fa581709deac0c9ad65cca8a9e9beac660adcbd493c798a"}, -] - [[package]] name = "pyyaml" version = "6.0.2" @@ -1259,18 +1247,6 @@ files = [ {file = "types_python_dateutil-2.9.0.20241003-py3-none-any.whl", hash = "sha256:250e1d8e80e7bbc3a6c99b907762711d1a1cdd00e978ad39cb5940f6f0a87f3d"}, ] -[[package]] -name = "types-pytz" -version = "2024.2.0.20241003" -description = "Typing stubs for pytz" -optional = false -python-versions = ">=3.8" -groups = ["typing"] -files = [ - {file = "types-pytz-2024.2.0.20241003.tar.gz", hash = "sha256:575dc38f385a922a212bac00a7d6d2e16e141132a3c955078f4a4fd13ed6cb44"}, - {file = "types_pytz-2024.2.0.20241003-py3-none-any.whl", hash = "sha256:3e22df1336c0c6ad1d29163c8fda82736909eb977281cb823c57f8bae07118b7"}, -] - [[package]] name = "typing-extensions" version = "4.12.2" @@ -1315,7 +1291,7 @@ platformdirs = ">=3.9.1,<5" [package.extras] docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] -test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8) ; platform_python_implementation == \"PyPy\" or platform_python_implementation == \"CPython\" and sys_platform == \"win32\" and python_version >= \"3.13\"", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10) ; platform_python_implementation == \"CPython\""] [[package]] name = "watchdog" @@ -1367,18 +1343,18 @@ description = "Backport of pathlib-compatible object wrapper for zip files" optional = false python-versions = ">=3.9" groups = ["benchmark", "doc"] -markers = "python_version < \"3.10\"" +markers = "python_version == \"3.9\"" files = [ {file = "zipp-3.21.0-py3-none-any.whl", hash = "sha256:ac1bbe05fd2991f160ebce24ffbac5f6d11d83dc90891255885223d42b3cd931"}, {file = "zipp-3.21.0.tar.gz", hash = "sha256:2c9958f6430a2040341a52eb608ed6dd93ef4392e02ffe219417c1b28b5dd1f4"}, ] [package.extras] -check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\""] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] enabler = ["pytest-enabler (>=2.2)"] -test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] +test = ["big-O", "importlib-resources ; python_version < \"3.9\"", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] type = ["pytest-mypy"] [extras] @@ -1387,4 +1363,4 @@ test = ["time-machine"] [metadata] lock-version = "2.1" python-versions = ">=3.9" -content-hash = "dc470000c660e266dfac2de213fc4145c0877319afe6935de158ba5b8daefb8f" +content-hash = "73eefcf70e8f172108ed301f666b5c88f4f9e4783ba0f57640a164f4d1a30e8d" diff --git a/pyproject.toml b/pyproject.toml index 705f1359..55c6c1e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ Repository = "https://github.com/sdispater/pendulum" [tool.poetry.group.test.dependencies] pytest = "^7.1.2" -pytz = ">=2022.1" time-machine = ">=2.16.0" pytest-benchmark = "^4.0.0" @@ -51,7 +50,6 @@ pre-commit = "^3.0.0" [tool.poetry.group.typing.dependencies] mypy = "^1.3.0" types-python-dateutil = "^2.8.19" -types-pytz = ">=2022.7.1.2" [tool.poetry.group.dev.dependencies] babel = "^2.10.3" diff --git a/tests/datetime/test_comparison.py b/tests/datetime/test_comparison.py index c3cb0640..4e25f0d6 100644 --- a/tests/datetime/test_comparison.py +++ b/tests/datetime/test_comparison.py @@ -1,8 +1,8 @@ from __future__ import annotations -from datetime import datetime +import zoneinfo -import pytz +from datetime import datetime import pendulum @@ -99,7 +99,7 @@ def test_greater_than_false(): def test_greater_than_with_timezone_true(): d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") d2 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver") - d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 8, 59, 59)) + d3 = datetime(2000, 1, 1, 8, 59, 59, tzinfo=zoneinfo.ZoneInfo("America/Vancouver")) assert d1 > d2 assert d1 > d3 @@ -108,7 +108,7 @@ def test_greater_than_with_timezone_true(): def test_greater_than_with_timezone_false(): d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") d2 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver") - d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 9, 0, 1)) + d3 = datetime(2000, 1, 1, 9, 0, 1, tzinfo=zoneinfo.ZoneInfo("America/Vancouver")) assert not d1 > d2 assert not d1 > d3 @@ -144,7 +144,7 @@ def test_greater_than_or_equal_false(): def test_greater_than_or_equal_with_timezone_true(): d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") d2 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver") - d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 8, 59, 59)) + d3 = datetime(2000, 1, 1, 8, 59, 59, tzinfo=zoneinfo.ZoneInfo("America/Vancouver")) assert d1 >= d2 assert d1 >= d3 @@ -153,7 +153,7 @@ def test_greater_than_or_equal_with_timezone_true(): def test_greater_than_or_equal_with_timezone_false(): d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") d2 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver") - d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 9, 0, 1)) + d3 = datetime(2000, 1, 1, 9, 0, 1, tzinfo=zoneinfo.ZoneInfo("America/Vancouver")) assert not d1 >= d2 assert not d1 >= d3 @@ -180,7 +180,7 @@ def test_less_than_false(): def test_less_than_with_timezone_true(): d1 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver") d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") - d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0)) + d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto")) assert d1 < d2 assert d1 < d3 @@ -189,7 +189,7 @@ def test_less_than_with_timezone_true(): def test_less_than_with_timezone_false(): d1 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver") d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") - d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0)) + d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto")) assert not d1 < d2 assert not d1 < d3 @@ -225,7 +225,7 @@ def test_less_than_or_equal_false(): def test_less_than_or_equal_with_timezone_true(): d1 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver") d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") - d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0)) + d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto")) assert d1 <= d2 assert d1 <= d3 @@ -234,7 +234,7 @@ def test_less_than_or_equal_with_timezone_true(): def test_less_than_or_equal_with_timezone_false(): d1 = pendulum.datetime(2000, 1, 1, 9, 0, 1, tz="America/Vancouver") d2 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto") - d3 = pytz.timezone("America/Toronto").localize(datetime(2000, 1, 1, 12, 0, 0)) + d3 = datetime(2000, 1, 1, 12, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Toronto")) assert not d1 <= d2 assert not d1 <= d3 diff --git a/tests/test_helpers.py b/tests/test_helpers.py index e9317b97..a9660495 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,9 +1,10 @@ from __future__ import annotations +import zoneinfo + from datetime import datetime import pytest -import pytz import pendulum @@ -102,18 +103,17 @@ def test_precise_diff_timezone() -> None: assert_diff(diff, days=1, hours=5) assert diff.total_days == 1 - # pytz - paris_pytz = pytz.timezone("Europe/Paris") - toronto_pytz = pytz.timezone("America/Toronto") + paris_tz = zoneinfo.ZoneInfo("Europe/Paris") + toronto_tz = zoneinfo.ZoneInfo("America/Toronto") - dt1 = paris_pytz.localize(datetime(2013, 3, 31, 1, 30)) - dt2 = paris_pytz.localize(datetime(2013, 4, 1, 1, 30)) + dt1 = datetime(2013, 3, 31, 1, 30, tzinfo=paris_tz) + dt2 = datetime(2013, 4, 1, 1, 30, tzinfo=paris_tz) diff = precise_diff(dt1, dt2) assert_diff(diff, days=1, hours=0) assert diff.total_days == 1 - dt2 = toronto_pytz.localize(datetime(2013, 4, 1, 1, 30)) + dt2 = datetime(2013, 4, 1, 1, 30, tzinfo=toronto_tz) diff = precise_diff(dt1, dt2) assert_diff(diff, days=1, hours=5) diff --git a/tests/test_main.py b/tests/test_main.py index 011a6b1d..76033450 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,11 +1,11 @@ from __future__ import annotations +import zoneinfo + from datetime import date from datetime import datetime from datetime import time -import pytz - from dateutil import tz import pendulum @@ -25,8 +25,8 @@ def test_instance_with_aware_datetime() -> None: assert now.timezone_name == "Europe/Paris" -def test_instance_with_aware_datetime_pytz() -> None: - now = pendulum.instance(datetime.now(pytz.timezone("Europe/Paris"))) +def test_instance_with_aware_datetime_zoneinfo() -> None: + now = pendulum.instance(datetime.now(zoneinfo.ZoneInfo("Europe/Paris"))) assert now.timezone_name == "Europe/Paris" @@ -57,7 +57,7 @@ def test_instance_with_aware_time() -> None: def test_safe_timezone_with_tzinfo_objects() -> None: - tz = _safe_timezone(pytz.timezone("Europe/Paris")) + tz = _safe_timezone(zoneinfo.ZoneInfo("Europe/Paris")) assert isinstance(tz, Timezone) assert tz.name == "Europe/Paris" diff --git a/tests/time/test_sub.py b/tests/time/test_sub.py index 1a957ad7..6d05d31e 100644 --- a/tests/time/test_sub.py +++ b/tests/time/test_sub.py @@ -1,10 +1,11 @@ from __future__ import annotations +import zoneinfo + from datetime import time from datetime import timedelta import pytest -import pytz import pendulum @@ -87,7 +88,7 @@ def test_subtract_time(): t = Time(12, 34, 56) t1 = Time(1, 1, 1) t2 = time(1, 1, 1) - t3 = time(1, 1, 1, tzinfo=pytz.timezone("Europe/Paris")) + t3 = time(1, 1, 1, tzinfo=zoneinfo.ZoneInfo("Europe/Paris")) diff = t - t1 assert isinstance(diff, pendulum.Duration)