Skip to content

Commit 81e8560

Browse files
committed
Fix lint issues
1 parent ece60b6 commit 81e8560

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

clock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ translations = {{}}
192192
for k, v in d.items():
193193
v = (
194194
self.format_dict(v, tab + 1)
195-
if isinstance(v, (dict, LocaleDataDict))
195+
if isinstance(v, dict | LocaleDataDict)
196196
else repr(v)
197197
)
198198

src/pendulum/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from functools import cache
66
from typing import TYPE_CHECKING
77
from typing import Any
8-
from typing import Union
98
from typing import cast
109
from typing import overload
1110

@@ -92,13 +91,13 @@ def _safe_timezone(
9291
Creates a timezone instance
9392
from a string, Timezone, TimezoneInfo or integer offset.
9493
"""
95-
if isinstance(obj, (Timezone, FixedTimezone)):
94+
if isinstance(obj, Timezone | FixedTimezone):
9695
return obj
9796

9897
if obj is None or obj == "local":
9998
return local_timezone()
10099

101-
if isinstance(obj, (int, float)):
100+
if isinstance(obj, int | float):
102101
obj = int(obj * 60 * 60)
103102
elif isinstance(obj, _datetime.tzinfo):
104103
# zoneinfo
@@ -117,7 +116,7 @@ def _safe_timezone(
117116

118117
obj = int(offset.total_seconds())
119118

120-
obj = cast("Union[str, int]", obj)
119+
obj = cast("str | int", obj)
121120

122121
return timezone(obj)
123122

@@ -227,7 +226,7 @@ def instance(
227226
"""
228227
Create a DateTime/Date/Time instance from a datetime/date/time native one.
229228
"""
230-
if isinstance(obj, (DateTime, Date, Time)):
229+
if isinstance(obj, DateTime | Date | Time):
231230
return obj
232231

233232
if isinstance(obj, _datetime.date) and not isinstance(obj, _datetime.datetime):

src/pendulum/datetime.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
from typing import TYPE_CHECKING
88
from typing import Any
9-
from typing import Callable
109
from typing import ClassVar
11-
from typing import Optional
1210
from typing import cast
1311
from typing import overload
1412

@@ -42,7 +40,9 @@
4240

4341

4442
if TYPE_CHECKING:
45-
from typing_extensions import Literal
43+
from collections.abc import Callable
44+
from typing import Literal
45+
4646
from typing_extensions import Self
4747
from typing_extensions import SupportsIndex
4848

@@ -268,7 +268,7 @@ def offset_hours(self) -> float | None:
268268

269269
@property
270270
def timezone(self) -> Timezone | FixedTimezone | None:
271-
if not isinstance(self.tzinfo, (Timezone, FixedTimezone)):
271+
if not isinstance(self.tzinfo, Timezone | FixedTimezone):
272272
return None
273273

274274
return self.tzinfo
@@ -1006,7 +1006,7 @@ def nth_of(self, unit: str, nth: int, day_of_week: WeekDay) -> Self:
10061006
if unit not in ["month", "quarter", "year"]:
10071007
raise ValueError(f'Invalid unit "{unit}" for first_of()')
10081008

1009-
dt = cast("Optional[Self]", getattr(self, f"_nth_of_{unit}")(nth, day_of_week))
1009+
dt = cast("Self | None", getattr(self, f"_nth_of_{unit}")(nth, day_of_week))
10101010
if not dt:
10111011
raise PendulumException(
10121012
f"Unable to find occurrence {nth}"

src/pendulum/duration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def __floordiv__(self, other: timedelta) -> int: ...
381381
def __floordiv__(self, other: int) -> Self: ...
382382

383383
def __floordiv__(self, other: int | timedelta) -> int | Duration:
384-
if not isinstance(other, (int, timedelta)):
384+
if not isinstance(other, int | timedelta):
385385
return NotImplemented
386386

387387
usec = self._to_microseconds()
@@ -407,7 +407,7 @@ def __truediv__(self, other: timedelta) -> float: ...
407407
def __truediv__(self, other: float) -> Self: ...
408408

409409
def __truediv__(self, other: int | float | timedelta) -> Self | float:
410-
if not isinstance(other, (int, float, timedelta)):
410+
if not isinstance(other, int | float | timedelta):
411411
return NotImplemented
412412

413413
usec = self._to_microseconds()

src/pendulum/formatting/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from re import Match
77
from typing import TYPE_CHECKING
88
from typing import Any
9-
from typing import Callable
109
from typing import ClassVar
1110
from typing import cast
1211

@@ -16,6 +15,7 @@
1615

1716

1817
if TYPE_CHECKING:
18+
from collections.abc import Callable
1919
from collections.abc import Sequence
2020

2121
from pendulum import Timezone

src/pendulum/parsing/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from datetime import datetime
1010
from datetime import time
1111
from typing import Any
12-
from typing import Optional
1312
from typing import cast
1413

1514
from dateutil import parser
@@ -90,7 +89,7 @@ def _normalize(
9089
return parsed
9190

9291
if isinstance(parsed, time):
93-
now = cast("Optional[datetime]", options["now"]) or datetime.now()
92+
now = cast("datetime | None", options["now"]) or datetime.now()
9493

9594
return datetime(
9695
now.year,

src/pendulum/time.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import time
66
from datetime import timedelta
77
from typing import TYPE_CHECKING
8-
from typing import Optional
98
from typing import cast
109
from typing import overload
1110

@@ -21,7 +20,8 @@
2120

2221

2322
if TYPE_CHECKING:
24-
from typing_extensions import Literal
23+
from typing import Literal
24+
2525
from typing_extensions import Self
2626
from typing_extensions import SupportsIndex
2727

@@ -174,7 +174,7 @@ def __sub__(self, other: time) -> pendulum.Duration: ...
174174
def __sub__(self, other: datetime.timedelta) -> Time: ...
175175

176176
def __sub__(self, other: time | datetime.timedelta) -> pendulum.Duration | Time:
177-
if not isinstance(other, (Time, time, timedelta)):
177+
if not isinstance(other, Time | time | timedelta):
178178
return NotImplemented
179179

180180
if isinstance(other, timedelta):
@@ -197,7 +197,7 @@ def __rsub__(self, other: time) -> pendulum.Duration: ...
197197
def __rsub__(self, other: datetime.timedelta) -> Time: ...
198198

199199
def __rsub__(self, other: time | datetime.timedelta) -> pendulum.Duration | Time:
200-
if not isinstance(other, (Time, time)):
200+
if not isinstance(other, Time | time):
201201
return NotImplemented
202202

203203
if isinstance(other, time):
@@ -284,7 +284,7 @@ def replace(
284284
minute,
285285
second,
286286
microsecond,
287-
tzinfo=cast("Optional[datetime.tzinfo]", tzinfo),
287+
tzinfo=cast("datetime.tzinfo | None", tzinfo),
288288
fold=fold,
289289
)
290290
return self.__class__(

0 commit comments

Comments
 (0)