Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ jobs:
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install --only main --only test -vvv
run: poetry install --only main --only test --only typing -vvv

- name: Run type checking
run: poetry run mypy

- name: Test Pure Python
run: |
Expand Down
11 changes: 0 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,3 @@ repos:
exclude: ^build\.py$
args:
- --py37-plus

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- id: mypy
pass_filenames: false
exclude: ^build\.py$
additional_dependencies:
- pytest>=7.1.2
- types-backports
- types-python-dateutil
2 changes: 1 addition & 1 deletion pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _safe_timezone(
elif isinstance(obj, _datetime.tzinfo):
# zoneinfo
if hasattr(obj, "key"):
obj = obj.key # type: ignore
obj = obj.key
# pytz
elif hasattr(obj, "localize"):
obj = obj.zone # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def __add__(self, other: timedelta) -> Date:

return self._add_timedelta(other)

@overload
@overload # type: ignore[override]
def __sub__(self, delta: timedelta) -> Date:
...

Expand Down
4 changes: 2 additions & 2 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from pendulum.utils._compat import PY38

if TYPE_CHECKING:
from typing import Literal
from pendulum.utils._compat import Literal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to from typing_extensions import Literal so that pyright is supported



class DateTime(datetime.datetime, Date):
Expand Down Expand Up @@ -1349,7 +1349,7 @@ def __reduce__(
]:
return self.__reduce_ex__(2)

def __reduce_ex__( # type: ignore[override]
def __reduce_ex__(
self, protocol: int
) -> tuple[
type[DateTime], tuple[int, int, int, int, int, int, int, datetime.tzinfo | None]
Expand Down
4 changes: 2 additions & 2 deletions pendulum/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
from pendulum._extensions._helpers import timestamp
from pendulum._extensions._helpers import week_day
except ImportError:
from pendulum._extensions.helpers import PreciseDiff # type: ignore[misc]
from pendulum._extensions.helpers import PreciseDiff # type: ignore[assignment]
from pendulum._extensions.helpers import days_in_year
from pendulum._extensions.helpers import is_leap
from pendulum._extensions.helpers import is_long_year
from pendulum._extensions.helpers import local_time
from pendulum._extensions.helpers import precise_diff # type: ignore[misc]
from pendulum._extensions.helpers import precise_diff # type: ignore[assignment]
from pendulum._extensions.helpers import timestamp
from pendulum._extensions.helpers import week_day

Expand Down
3 changes: 1 addition & 2 deletions pendulum/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
from pendulum.helpers import precise_diff

if TYPE_CHECKING:
from typing import SupportsIndex

from pendulum.helpers import PreciseDiff
from pendulum.locales.locale import Locale # noqa
from pendulum.utils._compat import SupportsIndex


class Interval(Duration):
Expand Down
2 changes: 1 addition & 1 deletion pendulum/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | I
),
)

if CDuration and isinstance(parsed, CDuration):
if CDuration and isinstance(parsed, CDuration): # type: ignore[truthy-function]
return pendulum.duration(
years=parsed.years,
months=parsed.months,
Expand Down
4 changes: 2 additions & 2 deletions pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from pendulum.parsing._iso8601 import Duration
from pendulum.parsing._iso8601 import parse_iso8601
except ImportError:
from pendulum.duration import Duration # type: ignore[misc]
from pendulum.parsing.iso8601 import parse_iso8601 # type: ignore[misc]
from pendulum.duration import Duration # type: ignore[assignment]
from pendulum.parsing.iso8601 import parse_iso8601 # type: ignore[assignment]

COMMON = re.compile(
# Date (optional) # noqa: E800
Expand Down
4 changes: 2 additions & 2 deletions pendulum/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pendulum.mixins.default import FormattableMixin

if TYPE_CHECKING:
from typing import Literal
from pendulum.utils._compat import Literal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to from typing_extensions import Literal so that pyright is supported



class Time(FormattableMixin, time):
Expand Down Expand Up @@ -292,7 +292,7 @@ def __reduce__(
) -> tuple[type[Time], tuple[int, int, int, int, datetime.tzinfo | None]]:
return self.__reduce_ex__(2)

def __reduce_ex__( # type: ignore[override]
def __reduce_ex__(
self, protocol: int
) -> tuple[type[Time], tuple[int, int, int, int, datetime.tzinfo | None]]:
return self.__class__, self._get_state(protocol)
Expand Down
10 changes: 2 additions & 8 deletions pendulum/tz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from __future__ import annotations

import sys

from pendulum.tz.local_timezone import get_local_timezone
from pendulum.tz.local_timezone import set_local_timezone
from pendulum.tz.local_timezone import test_local_timezone
from pendulum.tz.timezone import UTC
from pendulum.tz.timezone import FixedTimezone
from pendulum.tz.timezone import Timezone

if sys.version_info >= (3, 9):
from importlib import resources
else:
import importlib_resources as resources
from pendulum.utils._compat import resources

PRE_TRANSITION = "pre"
POST_TRANSITION = "post"
Expand All @@ -27,7 +21,7 @@ def timezones() -> tuple[str, ...]:
global _timezones

if _timezones is None:
with resources.files("tzdata").joinpath("zones").open() as f:
with resources.files("tzdata").joinpath("zones").open() as f: # type: ignore[no-untyped-call]
_timezones = tuple(tz.strip() for tz in f.readlines())

return _timezones
Expand Down
2 changes: 1 addition & 1 deletion pendulum/tz/local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _get_windows_timezone() -> Timezone:

else:

def _get_windows_timezone() -> Timezone:
def _get_windows_timezone() -> Timezone: # type: ignore[empty-body]
...


Expand Down
14 changes: 13 additions & 1 deletion pendulum/utils/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
PY38 = sys.version_info[:2] >= (3, 8)

if sys.version_info < (3, 9):
import importlib_resources as resources

from backports import zoneinfo
else:
import zoneinfo

__all__ = ["zoneinfo"]
from importlib import resources


if sys.version_info < (3, 8):
from typing_extensions import Literal
Copy link
Copy Markdown
Contributor

@bryanforbes bryanforbes Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliasing things like Literal is not supported in pyright. I'll add a comment where Literal is being used to show how it should be imported to prevent typing_extensions from becoming a runtime dependency.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only supporting mypy check in our pipelines right now and I stick to how mypy works (never worked with pyright, but it sounds like it's not compatible with mypy).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyright and mypy work pretty hard to be compatible with one another. pyright does an early scan for some special forms to speed things up, and the Literal import is one of those. This is one of the few differences (aside from pyright supporting more PEPs) between pyright and mypy. The other thing to take into account is that pyright is the type checker that is included by default with Visual Studio Code's Python extension.

from typing_extensions import SupportsIndex
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes typing_extensions a runtime dependency. Is that desired?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not 😆. I will need to rework this PR anyway since typing fails depending on the version of Python it's run on.

else:
from typing import Literal
from typing import SupportsIndex

__all__ = ["zoneinfo", "resources", "SupportsIndex", "Literal"]
Loading