From b0f928d5f7cead492a24bad76b4f877b8c53864d Mon Sep 17 00:00:00 2001 From: Marcin Rudolf Date: Sat, 9 Nov 2024 06:36:56 +0100 Subject: [PATCH] linter fixes --- poetry.lock | 29 ++++++++++++++++++++++++++- pyproject.toml | 1 + src/pendulum/__init__.py | 18 ++++++----------- src/pendulum/date.py | 9 +++------ src/pendulum/datetime.py | 12 ++++------- src/pendulum/duration.py | 20 +++++++++---------- src/pendulum/formatting/formatter.py | 2 +- src/pendulum/helpers.py | 3 +-- src/pendulum/interval.py | 18 ++++++----------- src/pendulum/parsing/__init__.py | 3 ++- src/pendulum/parsing/iso8601.py | 5 +++-- src/pendulum/testing/traveller.py | 3 +-- src/pendulum/time.py | 12 ++++------- src/pendulum/tz/__init__.py | 10 ++++++++-- src/pendulum/tz/local_timezone.py | 3 ++- src/pendulum/utils/_zoneinfo.py | 30 ++++++++++------------------ 16 files changed, 89 insertions(+), 89 deletions(-) diff --git a/poetry.lock b/poetry.lock index c79a1135..fa11365e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -979,6 +979,33 @@ files = [ [package.extras] full = ["numpy"] +[[package]] +name = "ruff" +version = "0.7.3" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.7.3-py3-none-linux_armv6l.whl", hash = "sha256:34f2339dc22687ec7e7002792d1f50712bf84a13d5152e75712ac08be565d344"}, + {file = "ruff-0.7.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:fb397332a1879b9764a3455a0bb1087bda876c2db8aca3a3cbb67b3dbce8cda0"}, + {file = "ruff-0.7.3-py3-none-macosx_11_0_arm64.whl", hash = "sha256:37d0b619546103274e7f62643d14e1adcbccb242efda4e4bdb9544d7764782e9"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d59f0c3ee4d1a6787614e7135b72e21024875266101142a09a61439cb6e38a5"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:44eb93c2499a169d49fafd07bc62ac89b1bc800b197e50ff4633aed212569299"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6d0242ce53f3a576c35ee32d907475a8d569944c0407f91d207c8af5be5dae4e"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:6b6224af8b5e09772c2ecb8dc9f3f344c1aa48201c7f07e7315367f6dd90ac29"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c50f95a82b94421c964fae4c27c0242890a20fe67d203d127e84fbb8013855f5"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7f3eff9961b5d2644bcf1616c606e93baa2d6b349e8aa8b035f654df252c8c67"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8963cab06d130c4df2fd52c84e9f10d297826d2e8169ae0c798b6221be1d1d2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:61b46049d6edc0e4317fb14b33bd693245281a3007288b68a3f5b74a22a0746d"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:10ebce7696afe4644e8c1a23b3cf8c0f2193a310c18387c06e583ae9ef284de2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:3f36d56326b3aef8eeee150b700e519880d1aab92f471eefdef656fd57492aa2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5d024301109a0007b78d57ab0ba190087b43dce852e552734ebf0b0b85e4fb16"}, + {file = "ruff-0.7.3-py3-none-win32.whl", hash = "sha256:4ba81a5f0c5478aa61674c5a2194de8b02652f17addf8dfc40c8937e6e7d79fc"}, + {file = "ruff-0.7.3-py3-none-win_amd64.whl", hash = "sha256:588a9ff2fecf01025ed065fe28809cd5a53b43505f48b69a1ac7707b1b7e4088"}, + {file = "ruff-0.7.3-py3-none-win_arm64.whl", hash = "sha256:1713e2c5545863cdbfe2cbce21f69ffaf37b813bfd1fb3b90dc9a6f1963f5a8c"}, + {file = "ruff-0.7.3.tar.gz", hash = "sha256:e1d1ba2e40b6e71a61b063354d04be669ab0d39c352461f3d789cac68b54a313"}, +] + [[package]] name = "setuptools" version = "69.0.2" @@ -1247,4 +1274,4 @@ test = [] [metadata] lock-version = "2.0" python-versions = ">=3.8" -content-hash = "899aae832080b5159e5aeab21738994fb9716e924eb446e0ac29074bd0e65625" +content-hash = "5297e551e4299dc820b70076fa624ae58d9a38d2ec283903ef98bfb815989f68" diff --git a/pyproject.toml b/pyproject.toml index 316f8e02..a129a7be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,7 @@ tox = "^4.0.0" # [tool.poetry.group.benchmark.dependencies] # pytest-codspeed = "^1.2.2" +ruff = "^0.7.3" [tool.poetry.group.build.dependencies] maturin = ">=1.0,<2.0" diff --git a/src/pendulum/__init__.py b/src/pendulum/__init__.py index 3863b760..1a6eb324 100644 --- a/src/pendulum/__init__.py +++ b/src/pendulum/__init__.py @@ -59,18 +59,15 @@ @overload -def timezone(name: int) -> FixedTimezone: - ... +def timezone(name: int) -> FixedTimezone: ... @overload -def timezone(name: str) -> Timezone: - ... +def timezone(name: str) -> Timezone: ... @overload -def timezone(name: str | int) -> Timezone | FixedTimezone: - ... +def timezone(name: str | int) -> Timezone | FixedTimezone: ... def timezone(name: str | int) -> Timezone | FixedTimezone: @@ -205,24 +202,21 @@ def time(hour: int, minute: int = 0, second: int = 0, microsecond: int = 0) -> T def instance( obj: _datetime.datetime, tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC, -) -> DateTime: - ... +) -> DateTime: ... @overload def instance( obj: _datetime.date, tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC, -) -> Date: - ... +) -> Date: ... @overload def instance( obj: _datetime.time, tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC, -) -> Time: - ... +) -> Time: ... def instance( diff --git a/src/pendulum/date.py b/src/pendulum/date.py index e7b862c5..892c1193 100644 --- a/src/pendulum/date.py +++ b/src/pendulum/date.py @@ -257,16 +257,13 @@ def __add__(self, other: timedelta) -> Self: return self._add_timedelta(other) @overload # type: ignore[override] # this is only needed because of Python 3.7 - def __sub__(self, __delta: timedelta) -> Self: - ... + def __sub__(self, __delta: timedelta) -> Self: ... @overload - def __sub__(self, __dt: datetime) -> NoReturn: - ... + def __sub__(self, __dt: datetime) -> NoReturn: ... @overload - def __sub__(self, __dt: Self) -> Interval: - ... + def __sub__(self, __dt: Self) -> Interval: ... def __sub__(self, other: timedelta | date) -> Self | Interval: if isinstance(other, timedelta): diff --git a/src/pendulum/datetime.py b/src/pendulum/datetime.py index 752a9ac8..c3fddd87 100644 --- a/src/pendulum/datetime.py +++ b/src/pendulum/datetime.py @@ -146,13 +146,11 @@ def instance( @overload @classmethod - def now(cls, tz: datetime.tzinfo | None = None) -> Self: - ... + def now(cls, tz: datetime.tzinfo | None = None) -> Self: ... @overload @classmethod - def now(cls, tz: str | Timezone | FixedTimezone | None = None) -> Self: - ... + def now(cls, tz: str | Timezone | FixedTimezone | None = None) -> Self: ... @classmethod def now( @@ -1186,12 +1184,10 @@ def average( # type: ignore[override] ) @overload # type: ignore[override] - def __sub__(self, other: datetime.timedelta) -> Self: - ... + def __sub__(self, other: datetime.timedelta) -> Self: ... @overload - def __sub__(self, other: DateTime) -> Interval: - ... + def __sub__(self, other: DateTime) -> Interval: ... def __sub__(self, other: datetime.datetime | datetime.timedelta) -> Self | Interval: if isinstance(other, datetime.timedelta): diff --git a/src/pendulum/duration.py b/src/pendulum/duration.py index a4875fca..8a19548d 100644 --- a/src/pendulum/duration.py +++ b/src/pendulum/duration.py @@ -375,12 +375,10 @@ def __mul__(self, other: int | float) -> Self: __rmul__ = __mul__ @overload - def __floordiv__(self, other: timedelta) -> int: - ... + def __floordiv__(self, other: timedelta) -> int: ... @overload - def __floordiv__(self, other: int) -> Self: - ... + def __floordiv__(self, other: int) -> Self: ... def __floordiv__(self, other: int | timedelta) -> int | Duration: if not isinstance(other, (int, timedelta)): @@ -389,7 +387,8 @@ def __floordiv__(self, other: int | timedelta) -> int | Duration: usec = self._to_microseconds() if isinstance(other, timedelta): return cast( - int, usec // other._to_microseconds() # type: ignore[attr-defined] + int, + usec // other._to_microseconds(), # type: ignore[attr-defined] ) if isinstance(other, int): @@ -402,12 +401,10 @@ def __floordiv__(self, other: int | timedelta) -> int | Duration: ) @overload - def __truediv__(self, other: timedelta) -> float: - ... + def __truediv__(self, other: timedelta) -> float: ... @overload - def __truediv__(self, other: float) -> Self: - ... + def __truediv__(self, other: float) -> Self: ... def __truediv__(self, other: int | float | timedelta) -> Self | float: if not isinstance(other, (int, float, timedelta)): @@ -416,7 +413,8 @@ def __truediv__(self, other: int | float | timedelta) -> Self | float: usec = self._to_microseconds() if isinstance(other, timedelta): return cast( - float, usec / other._to_microseconds() # type: ignore[attr-defined] + float, + usec / other._to_microseconds(), # type: ignore[attr-defined] ) if isinstance(other, int): @@ -443,7 +441,7 @@ def __truediv__(self, other: int | float | timedelta) -> Self | float: def __mod__(self, other: timedelta) -> Self: if isinstance(other, timedelta): - r = self._to_microseconds() % other._to_microseconds() # type: ignore[attr-defined] # noqa: E501 + r = self._to_microseconds() % other._to_microseconds() # type: ignore[attr-defined] return self.__class__(0, 0, r) diff --git a/src/pendulum/formatting/formatter.py b/src/pendulum/formatting/formatter.py index ee04063f..75a22bae 100644 --- a/src/pendulum/formatting/formatter.py +++ b/src/pendulum/formatting/formatter.py @@ -38,7 +38,7 @@ _MATCH_TIMESTAMP = r"[+-]?\d+(\.\d{1,6})?" _MATCH_WORD = ( "(?i)[0-9]*" - "['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+" + "['a-z\u00a0-\u05ff\u0700-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]+" r"|[\u0600-\u06FF/]+(\s*?[\u0600-\u06FF]+){1,2}" ) _MATCH_TIMEZONE = "[A-Za-z0-9-+]+(/[A-Za-z0-9-+_]+)?" diff --git a/src/pendulum/helpers.py b/src/pendulum/helpers.py index 5d5fe8e5..c9dc9b51 100644 --- a/src/pendulum/helpers.py +++ b/src/pendulum/helpers.py @@ -62,8 +62,7 @@ def add_duration( minutes: int = 0, seconds: float = 0, microseconds: int = 0, -) -> _DT: - ... +) -> _DT: ... @overload diff --git a/src/pendulum/interval.py b/src/pendulum/interval.py index 19c91a6a..6e85655d 100644 --- a/src/pendulum/interval.py +++ b/src/pendulum/interval.py @@ -37,8 +37,7 @@ def __new__( start: pendulum.DateTime | datetime, end: pendulum.DateTime | datetime, absolute: bool = False, - ) -> Self: - ... + ) -> Self: ... @overload def __new__( @@ -46,8 +45,7 @@ def __new__( start: pendulum.Date | date, end: pendulum.Date | date, absolute: bool = False, - ) -> Self: - ... + ) -> Self: ... def __new__( cls, @@ -351,12 +349,10 @@ def __mul__(self, other: int | float) -> Duration: # type: ignore[override] __rmul__ = __mul__ # type: ignore[assignment] @overload # type: ignore[override] - def __floordiv__(self, other: timedelta) -> int: - ... + def __floordiv__(self, other: timedelta) -> int: ... @overload - def __floordiv__(self, other: int) -> Duration: - ... + def __floordiv__(self, other: int) -> Duration: ... def __floordiv__(self, other: int | timedelta) -> int | Duration: return self.as_duration().__floordiv__(other) @@ -364,12 +360,10 @@ def __floordiv__(self, other: int | timedelta) -> int | Duration: __div__ = __floordiv__ # type: ignore[assignment] @overload # type: ignore[override] - def __truediv__(self, other: timedelta) -> float: - ... + def __truediv__(self, other: timedelta) -> float: ... @overload - def __truediv__(self, other: float) -> Duration: - ... + def __truediv__(self, other: float) -> Duration: ... def __truediv__(self, other: float | timedelta) -> Duration | float: return self.as_duration().__truediv__(other) diff --git a/src/pendulum/parsing/__init__.py b/src/pendulum/parsing/__init__.py index 761f52c5..2927135e 100644 --- a/src/pendulum/parsing/__init__.py +++ b/src/pendulum/parsing/__init__.py @@ -44,7 +44,8 @@ " )" ")?" # Time (optional) # noqa: ERA001 - "(?P