Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Nov 9, 2024
1 parent b0aeb53 commit b0f928d
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 89 deletions.
29 changes: 28 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 6 additions & 12 deletions src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions src/pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 9 additions & 11 deletions src/pendulum/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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):
Expand All @@ -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)):
Expand All @@ -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):
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-+_]+)?"
Expand Down
3 changes: 1 addition & 2 deletions src/pendulum/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def add_duration(
minutes: int = 0,
seconds: float = 0,
microseconds: int = 0,
) -> _DT:
...
) -> _DT: ...


@overload
Expand Down
18 changes: 6 additions & 12 deletions src/pendulum/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ def __new__(
start: pendulum.DateTime | datetime,
end: pendulum.DateTime | datetime,
absolute: bool = False,
) -> Self:
...
) -> Self: ...

@overload
def __new__(
cls,
start: pendulum.Date | date,
end: pendulum.Date | date,
absolute: bool = False,
) -> Self:
...
) -> Self: ...

def __new__(
cls,
Expand Down Expand Up @@ -351,25 +349,21 @@ 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)

__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)
Expand Down
3 changes: 2 additions & 1 deletion src/pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
" )"
")?"
# Time (optional) # noqa: ERA001
"(?P<time>" r" (?P<timesep>\ )?" # Separator (space)
"(?P<time>"
r" (?P<timesep>\ )?" # Separator (space)
# HH:mm:ss (optional mm and ss)
r" (?P<hour>\d{1,2}):(?P<minute>\d{1,2})?(?::(?P<second>\d{1,2}))?"
# Subsecond part (optional)
Expand Down
5 changes: 3 additions & 2 deletions src/pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
" )"
")?"
# Time (optional) # noqa: ERA001
"(?P<time>" r" (?P<timesep>[T\ ])?" # Separator (T or space)
"(?P<time>"
r" (?P<timesep>[T\ ])?" # Separator (T or space)
# HH:mm:ss (optional mm and ss)
r" (?P<hour>\d{1,2})(?P<minsep>:)?(?P<minute>\d{1,2})?(?P<secsep>:)?(?P<second>\d{1,2})?" # noqa: E501
r" (?P<hour>\d{1,2})(?P<minsep>:)?(?P<minute>\d{1,2})?(?P<secsep>:)?(?P<second>\d{1,2})?"
# Subsecond part (optional)
" (?P<subsecondsection>"
" (?:[.,])" # Subsecond separator (optional)
Expand Down
3 changes: 1 addition & 2 deletions src/pendulum/testing/traveller.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def __exit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType,
) -> None:
...
) -> None: ...

def _not_implemented(self) -> NotImplementedError:
return NotImplementedError()
Expand Down
12 changes: 4 additions & 8 deletions src/pendulum/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ def __add__(self, other: datetime.timedelta) -> Time:
return self.add_timedelta(other)

@overload
def __sub__(self, other: time) -> pendulum.Duration:
...
def __sub__(self, other: time) -> pendulum.Duration: ...

@overload
def __sub__(self, other: datetime.timedelta) -> Time:
...
def __sub__(self, other: datetime.timedelta) -> Time: ...

def __sub__(self, other: time | datetime.timedelta) -> pendulum.Duration | Time:
if not isinstance(other, (Time, time, timedelta)):
Expand All @@ -193,12 +191,10 @@ def __sub__(self, other: time | datetime.timedelta) -> pendulum.Duration | Time:
return other.diff(self, False)

@overload
def __rsub__(self, other: time) -> pendulum.Duration:
...
def __rsub__(self, other: time) -> pendulum.Duration: ...

@overload
def __rsub__(self, other: datetime.timedelta) -> Time:
...
def __rsub__(self, other: datetime.timedelta) -> Time: ...

def __rsub__(self, other: time | datetime.timedelta) -> pendulum.Duration | Time:
if not isinstance(other, (Time, time)):
Expand Down
10 changes: 8 additions & 2 deletions src/pendulum/tz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pendulum.tz.timezone import UTC
from pendulum.tz.timezone import FixedTimezone
from pendulum.tz.timezone import Timezone
from pendulum.utils._zoneinfo import available_timezones
from pendulum.utils._compat import resources


PRE_TRANSITION = "pre"
Expand All @@ -22,7 +22,13 @@


def timezones() -> tuple[str, ...]:
return available_timezones()
global _timezones

if _timezones is None:
with cast(Path, resources.files("tzdata").joinpath("zones")).open() as f:
_timezones = tuple(tz.strip() for tz in f.readlines())

return _timezones


def fixed_timezone(offset: int) -> FixedTimezone:
Expand Down
3 changes: 2 additions & 1 deletion src/pendulum/tz/local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def _get_unix_timezone(_root: str = "/") -> Timezone:
line = line[match.end() :]
etctz = line[
: cast(
re.Match, end_re.search(line) # type: ignore[type-arg]
re.Match,
end_re.search(line), # type: ignore[type-arg]
).start()
]

Expand Down
Loading

0 comments on commit b0f928d

Please sign in to comment.