Skip to content
Merged
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
29 changes: 0 additions & 29 deletions .flake8

This file was deleted.

48 changes: 5 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,20 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: ^tests/.*/fixtures/.*
- id: end-of-file-fixer
exclude: ^tests/.*/fixtures/.*
- id: debug-statements

- repo: https://github.com/hadialqattan/pycln
rev: v2.1.1
hooks:
- id: pycln
args: [ --all ]

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [ --add-import, from __future__ import annotations, --lines-after-imports, "-1" ]

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: &flake8_deps
- flake8-broken-line==0.5.0
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10.0
- flake8-eradicate==1.3.0
- flake8-quotes==3.3.1
- flake8-simplify==0.19.2
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.1.2
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.3
- pep8-naming==0.13.1

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: *flake8_deps

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
hooks:
- id: pyupgrade
exclude: ^build\.py$
args:
- --py37-plus
- id: ruff
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def meson(*args):
subprocess.call(["meson"] + list(args))
subprocess.call(["meson", *list(args)])


def _build():
Expand Down
3 changes: 0 additions & 3 deletions clock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class _LambdaCompiler(_GettextCompiler):


class LocaleCreate(Command):

name = "locale create"
description = "Creates locale translations."

Expand Down Expand Up @@ -229,7 +228,6 @@ translations = {{}}


class LocaleRecreate(Command):

name = "locale recreate"
description = "Recreate existing locales."

Expand All @@ -244,7 +242,6 @@ class LocaleRecreate(Command):


class WindowsTzDump(Command):

name = "windows dump-timezones"
description = "Dumps the mapping of Windows timezones to IANA timezones."

Expand Down
3 changes: 2 additions & 1 deletion pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pendulum.tz.timezone import FixedTimezone
from pendulum.tz.timezone import Timezone


_TEST_NOW: DateTime | None = None
_LOCALE = "en"
_WEEK_STARTS_AT = MONDAY
Expand Down Expand Up @@ -105,7 +106,7 @@ def _safe_timezone(
obj = obj.key
# pytz
elif hasattr(obj, "localize"):
obj = obj.zone # type: ignore
obj = obj.zone # type: ignore[attr-defined]
elif obj.tzname(None) == "UTC":
return UTC
else:
Expand Down
3 changes: 3 additions & 0 deletions pendulum/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


__version__ = "3.0.0a"
2 changes: 1 addition & 1 deletion pendulum/_extensions/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,6 @@ def _get_tzinfo_name(tzinfo: datetime.tzinfo | None) -> str | None:
return cast(Timezone, tzinfo).name
elif hasattr(tzinfo, "zone"):
# pytz timezone
return tzinfo.zone # type: ignore
return tzinfo.zone # type: ignore[no-any-return]

return None
1 change: 1 addition & 0 deletions pendulum/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The day constants
from __future__ import annotations


SUNDAY = 0
MONDAY = 1
TUESDAY = 2
Expand Down
12 changes: 8 additions & 4 deletions pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pendulum.interval import Interval
from pendulum.mixins.default import FormattableMixin


if TYPE_CHECKING:
from typing_extensions import Self
from typing_extensions import SupportsIndex
Expand Down Expand Up @@ -187,8 +188,9 @@ def is_anniversary(self, dt: date | None = None) -> bool:
return (self.month, self.day) == (instance.month, instance.day)

# the additional method for checking if today is the anniversary day
# the alias is provided to start using a new name and keep the backward compatibility
# the old name can be completely replaced with the new in one of the future versions
# the alias is provided to start using a new name and keep the backward
# compatibility the old name can be completely replaced with the new in
# one of the future versions
is_birthday = is_anniversary

# ADDITIONS AND SUBTRACTIONS
Expand Down Expand Up @@ -516,7 +518,8 @@ def first_of(self, unit: str, day_of_week: int | None = None) -> Self:
Returns an instance set to the first occurrence
of a given day of the week in the current unit.
If no day_of_week is provided, modify to the first day of the unit.
Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY.
Use the supplied consts to indicate the desired day_of_week,
ex. pendulum.MONDAY.

Supported units are month, quarter and year.

Expand All @@ -533,7 +536,8 @@ def last_of(self, unit: str, day_of_week: int | None = None) -> Self:
Returns an instance set to the last occurrence
of a given day of the week in the current unit.
If no day_of_week is provided, modify to the last day of the unit.
Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY.
Use the supplied consts to indicate the desired day_of_week,
ex. pendulum.MONDAY.

Supported units are month, quarter and year.

Expand Down
17 changes: 7 additions & 10 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pendulum.tz.timezone import FixedTimezone
from pendulum.tz.timezone import Timezone


if TYPE_CHECKING:
from typing_extensions import Literal
from typing_extensions import Self
Expand Down Expand Up @@ -913,10 +914,7 @@ def next(self, day_of_week: int | None = None, keep_time: bool = False) -> Self:
if day_of_week < SUNDAY or day_of_week > SATURDAY:
raise ValueError("Invalid day of week")

if keep_time:
dt = self
else:
dt = self.start_of("day")
dt = self if keep_time else self.start_of("day")

dt = dt.add(days=1)
while dt.day_of_week != day_of_week:
Expand All @@ -937,10 +935,7 @@ def previous(self, day_of_week: int | None = None, keep_time: bool = False) -> S
if day_of_week < SUNDAY or day_of_week > SATURDAY:
raise ValueError("Invalid day of week")

if keep_time:
dt = self
else:
dt = self.start_of("day")
dt = self if keep_time else self.start_of("day")

dt = dt.subtract(days=1)
while dt.day_of_week != day_of_week:
Expand All @@ -953,7 +948,8 @@ def first_of(self, unit: str, day_of_week: int | None = None) -> Self:
Returns an instance set to the first occurrence
of a given day of the week in the current unit.
If no day_of_week is provided, modify to the first day of the unit.
Use the supplied consts to indicate the desired day_of_week, ex. DateTime.MONDAY.
Use the supplied consts to indicate the desired day_of_week,
ex. DateTime.MONDAY.

Supported units are month, quarter and year.
"""
Expand All @@ -967,7 +963,8 @@ def last_of(self, unit: str, day_of_week: int | None = None) -> Self:
Returns an instance set to the last occurrence
of a given day of the week in the current unit.
If no day_of_week is provided, modify to the last day of the unit.
Use the supplied consts to indicate the desired day_of_week, ex. DateTime.MONDAY.
Use the supplied consts to indicate the desired day_of_week,
ex. DateTime.MONDAY.

Supported units are month, quarter and year.
"""
Expand Down
13 changes: 9 additions & 4 deletions pendulum/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pendulum.constants import US_PER_SECOND
from pendulum.utils._compat import PYPY


if TYPE_CHECKING:
from typing_extensions import Self

Expand Down Expand Up @@ -376,7 +377,9 @@ 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]
return cast(
int, usec // other._to_microseconds() # type: ignore[attr-defined]
)

if isinstance(other, int):
return self.__class__(
Expand All @@ -401,7 +404,9 @@ 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]
return cast(
float, usec / other._to_microseconds() # type: ignore[attr-defined]
)

if isinstance(other, int):
return self.__class__(
Expand All @@ -427,15 +432,15 @@ 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]
r = self._to_microseconds() % other._to_microseconds() # type: ignore[attr-defined] # noqa: E501

return self.__class__(0, 0, r)

return NotImplemented

def __divmod__(self, other: timedelta) -> tuple[int, Duration]:
if isinstance(other, timedelta):
q, r = divmod(self._to_microseconds(), other._to_microseconds()) # type: ignore[attr-defined]
q, r = divmod(self._to_microseconds(), other._to_microseconds()) # type: ignore[attr-defined] # noqa: E501

return q, self.__class__(0, 0, r)

Expand Down
9 changes: 7 additions & 2 deletions pendulum/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from __future__ import annotations

from .parsing.exceptions import ParserError # noqa
from pendulum.parsing.exceptions import ParserError


class PendulumException(Exception):

pass


__all__ = [
"ParserError",
"PendulumException",
]
1 change: 1 addition & 0 deletions pendulum/formatting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

from pendulum.formatting.formatter import Formatter


__all__ = ["Formatter"]
6 changes: 2 additions & 4 deletions pendulum/formatting/difference_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pendulum.locales.locale import Locale


if t.TYPE_CHECKING:
from pendulum import Duration

Expand Down Expand Up @@ -31,10 +32,7 @@ def format(
:param absolute: Whether it's an absolute difference or not
:param locale: The locale to use
"""
if locale is None:
locale = self._locale
else:
locale = Locale.load(locale)
locale = self._locale if locale is None else Locale.load(locale)

if diff.years > 0:
unit = "year"
Expand Down
15 changes: 6 additions & 9 deletions pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from pendulum.locales.locale import Locale


if TYPE_CHECKING:
from pendulum import Timezone

Expand Down Expand Up @@ -287,10 +288,7 @@ def _format_token(self, dt: pendulum.DateTime, token: str, locale: Locale) -> st
offset = dt.utcoffset() or datetime.timedelta()
minutes = offset.total_seconds() / 60

if minutes >= 0:
sign = "+"
else:
sign = "-"
sign = "+" if minutes >= 0 else "-"

hour, minute = divmod(abs(int(minutes)), 60)

Expand Down Expand Up @@ -395,9 +393,8 @@ def parse(
if not re.search("^" + pattern + "$", time):
raise ValueError(f"String does not match format {fmt}")

_get_parsed_values: Callable[
[Match[str]], Any
] = lambda m: self._get_parsed_values(m, parsed, loaded_locale, now)
def _get_parsed_values(m: Match[str]) -> Any:
return self._get_parsed_values(m, parsed, loaded_locale, now)

re.sub(pattern, _get_parsed_values, time)

Expand Down Expand Up @@ -502,9 +499,9 @@ def _check_parsed(
raise ValueError("Invalid date")

pm = parsed["meridiem"] == "pm"
validated["hour"] %= 12 # type: ignore
validated["hour"] %= 12 # type: ignore[operator]
if pm:
validated["hour"] += 12 # type: ignore
validated["hour"] += 12 # type: ignore[operator]

if validated["month"] is None:
if parsed["year"] is not None:
Expand Down
Loading