Skip to content

Commit

Permalink
make formats
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Dec 28, 2024
1 parent d652bdd commit adc533a
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ jobs:
- os: macos
target: aarch64
interpreter: 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10



runs-on: ${{ matrix.os }}-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: pip install pre-commit
- name: "Install Rust toolchain"
run: rustup component add rustfmt clippy
- run: pre-commit run --all-files
- run: make lint

Tests:
name: ${{ matrix.os }} / ${{ matrix.python-version }}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ dev:

lint:
poetry run mypy
pre-commit run --all-files

test:
PENDULUM_EXTENSIONS=0 poetry run pytest -q tests
poetry run pytest -q tests
poetry run pytest -q tests
9 changes: 5 additions & 4 deletions clock
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ translations = {{}}
def format_dict(self, d, tab=1):
s = ["{\n"]
for k, v in d.items():
if isinstance(v, (dict, LocaleDataDict)):
v = self.format_dict(v, tab + 1)
else:
v = repr(v)
v = (
self.format_dict(v, tab + 1)
if isinstance(v, (dict, LocaleDataDict))
else repr(v)
)

s.append(f"{' ' * tab}{k!r}: {v},\n")
s.append(f'{" " * (tab - 1)}}}')
Expand Down
21 changes: 1 addition & 20 deletions poetry.lock

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

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ruff = "^0.7.3"

[tool.poetry.group.build.dependencies]
maturin = ">=1.0,<2.0"
patchelf = ">=0.17"

[tool.poetry.extras]
test = ["time-machine"]
Expand All @@ -95,7 +94,7 @@ unfixable = [
"ERA", # do not autoremove commented out code
]
target-version = "py39"
line-length = 88
line-length = 100
extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
Expand Down
18 changes: 12 additions & 6 deletions src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@


@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 @@ -202,21 +205,24 @@ 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
6 changes: 4 additions & 2 deletions src/pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,12 @@ 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[Date]:
Expand Down
9 changes: 6 additions & 3 deletions src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ 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 @@ -1184,7 +1186,8 @@ 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[datetime.datetime]:
Expand Down
12 changes: 8 additions & 4 deletions src/pendulum/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,12 @@ 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 @@ -401,10 +403,12 @@ 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 Down
7 changes: 3 additions & 4 deletions src/pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,9 @@ def _check_parsed(
# we use it and don't go any further
if parsed["timestamp"] is not None:
str_us = str(parsed["timestamp"])
if "." in str_us:
microseconds = int(f'{str_us.split(".")[1].ljust(6, "0")}')
else:
microseconds = 0
microseconds = (
int(f"{str_us.split('.')[1].ljust(6, '0')}") if "." in str_us else 0
)

from pendulum.helpers import local_time

Expand Down
3 changes: 2 additions & 1 deletion src/pendulum/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def add_duration(
minutes: int = 0,
seconds: float = 0,
microseconds: int = 0,
) -> _DT: ...
) -> _DT:
...


@overload
Expand Down
12 changes: 8 additions & 4 deletions src/pendulum/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,25 @@ 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: 1 addition & 2 deletions src/pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
" )"
")?"
# 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
3 changes: 1 addition & 2 deletions src/pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
" )"
")?"
# 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})?"
# Subsecond part (optional)
Expand Down
3 changes: 2 additions & 1 deletion src/pendulum/testing/traveller.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ 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: 8 additions & 4 deletions src/pendulum/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ 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 @@ -191,10 +193,12 @@ 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
Loading

0 comments on commit adc533a

Please sign in to comment.