Skip to content

Commit 27ded3d

Browse files
committed
Update ruff config, use ruff format instead of black
1 parent 483443a commit 27ded3d

16 files changed

+98
-127
lines changed

.pre-commit-config.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ repos:
1111
exclude: ^tests/.*/fixtures/.*
1212
- id: debug-statements
1313

14-
- repo: https://github.com/psf/black
15-
rev: 23.7.0
16-
hooks:
17-
- id: black
18-
1914
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.0.291
15+
rev: v0.8.0
2116
hooks:
22-
- id: ruff
17+
- id: ruff
18+
- id: ruff-format
2319

2420
- repo: local
2521
hooks:

pyproject.toml

+27-22
Original file line numberDiff line numberDiff line change
@@ -85,47 +85,52 @@ test = ["time-machine"]
8585
[tool.maturin]
8686
module-name = "pendulum._pendulum"
8787

88-
8988
[tool.ruff]
9089
fix = true
91-
unfixable = [
92-
"ERA", # do not autoremove commented out code
93-
]
94-
target-version = "py39"
9590
line-length = 88
91+
target-version = "py39"
92+
extend-exclude = [
93+
# External to the project's coding standards:
94+
"docs/*",
95+
# Machine-generated, too many false-positives
96+
"src/pendulum/locales/*",
97+
# ruff disagrees with black when it comes to formatting
98+
"*.pyi",
99+
]
100+
101+
[tool.ruff.lint]
96102
extend-select = [
97-
"B", # flake8-bugbear
98-
"C4", # flake8-comprehensions
103+
"B", # flake8-bugbear
104+
"C4", # flake8-comprehensions
99105
"ERA", # flake8-eradicate/eradicate
100-
"I", # isort
101-
"N", # pep8-naming
106+
"I", # isort
107+
"N", # pep8-naming
102108
"PIE", # flake8-pie
103109
"PGH", # pygrep
104110
"RUF", # ruff checks
105111
"SIM", # flake8-simplify
112+
"T20", # flake8-print
106113
"TCH", # flake8-type-checking
107114
"TID", # flake8-tidy-imports
108-
"UP", # pyupgrade
115+
"UP", # pyupgrade
109116
]
110117
ignore = [
111118
"B904", # use 'raise ... from err'
112119
"B905", # use explicit 'strict=' parameter with 'zip()'
113-
"N818", # Exception name should be named with an Error suffix
114-
"RUF001",
120+
"N818",
121+
"RUF001"
115122
]
116-
extend-exclude = [
117-
# External to the project's coding standards:
118-
"docs/*",
119-
# Machine-generated, too many false-positives
120-
"src/pendulum/locales/*",
121-
# ruff disagrees with black when it comes to formatting
122-
"*.pyi",
123+
extend-safe-fixes = [
124+
"TCH", # move import from and to TYPE_CHECKING blocks
125+
]
126+
unfixable = [
127+
"ERA", # do not autoremove commented out code
123128
]
124129

125-
[tool.ruff.flake8-tidy-imports]
130+
[tool.ruff.lint.flake8-tidy-imports]
126131
ban-relative-imports = "all"
127132

128-
[tool.ruff.isort]
133+
[tool.ruff.lint.isort]
129134
force-single-line = true
130135
lines-between-types = 1
131136
lines-after-imports = 2
@@ -139,7 +144,7 @@ known-third-party = [
139144
]
140145
required-imports = ["from __future__ import annotations"]
141146

142-
[tool.ruff.extend-per-file-ignores]
147+
[tool.ruff.lint.extend-per-file-ignores]
143148
"build.py" = ["I002"]
144149
"clock" = ["RUF012"]
145150

src/pendulum/__init__.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,15 @@
5959

6060

6161
@overload
62-
def timezone(name: int) -> FixedTimezone:
63-
...
62+
def timezone(name: int) -> FixedTimezone: ...
6463

6564

6665
@overload
67-
def timezone(name: str) -> Timezone:
68-
...
66+
def timezone(name: str) -> Timezone: ...
6967

7068

7169
@overload
72-
def timezone(name: str | int) -> Timezone | FixedTimezone:
73-
...
70+
def timezone(name: str | int) -> Timezone | FixedTimezone: ...
7471

7572

7673
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
205202
def instance(
206203
obj: _datetime.datetime,
207204
tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC,
208-
) -> DateTime:
209-
...
205+
) -> DateTime: ...
210206

211207

212208
@overload
213209
def instance(
214210
obj: _datetime.date,
215211
tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC,
216-
) -> Date:
217-
...
212+
) -> Date: ...
218213

219214

220215
@overload
221216
def instance(
222217
obj: _datetime.time,
223218
tz: str | Timezone | FixedTimezone | _datetime.tzinfo | None = UTC,
224-
) -> Time:
225-
...
219+
) -> Time: ...
226220

227221

228222
def instance(
@@ -350,22 +344,27 @@ def interval(
350344
travel_back = _traveller.travel_back
351345

352346
__all__ = [
353-
"__version__",
354347
"DAYS_PER_WEEK",
355348
"HOURS_PER_DAY",
356349
"MINUTES_PER_HOUR",
357350
"MONTHS_PER_YEAR",
358351
"SECONDS_PER_DAY",
359352
"SECONDS_PER_HOUR",
360353
"SECONDS_PER_MINUTE",
354+
"UTC",
361355
"WEEKS_PER_YEAR",
362356
"YEARS_PER_CENTURY",
363357
"YEARS_PER_DECADE",
364358
"Date",
365359
"DateTime",
366360
"Duration",
361+
"FixedTimezone",
367362
"Formatter",
363+
"Interval",
364+
"Time",
365+
"Timezone",
368366
"WeekDay",
367+
"__version__",
369368
"date",
370369
"datetime",
371370
"duration",
@@ -377,18 +376,13 @@ def interval(
377376
"instance",
378377
"interval",
379378
"local",
379+
"local_timezone",
380380
"locale",
381381
"naive",
382382
"now",
383-
"set_locale",
384-
"week_ends_at",
385-
"week_starts_at",
386383
"parse",
387-
"Interval",
388-
"Time",
389-
"UTC",
390-
"local_timezone",
391384
"set_local_timezone",
385+
"set_locale",
392386
"test_local_timezone",
393387
"time",
394388
"timezone",
@@ -398,7 +392,7 @@ def interval(
398392
"travel",
399393
"travel_back",
400394
"travel_to",
401-
"FixedTimezone",
402-
"Timezone",
395+
"week_ends_at",
396+
"week_starts_at",
403397
"yesterday",
404398
]

src/pendulum/_helpers.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,8 @@ def precise_diff(
174174
d2.tzinfo if isinstance(d2, datetime.datetime) else None
175175
)
176176

177-
if (
178-
tzinfo1 is None
179-
and tzinfo2 is not None
180-
or tzinfo2 is None
181-
and tzinfo1 is not None
177+
if (tzinfo1 is None and tzinfo2 is not None) or (
178+
tzinfo2 is None and tzinfo1 is not None
182179
):
183180
raise ValueError(
184181
"Comparison between naive and aware datetimes is not supported"

src/pendulum/date.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,13 @@ def __add__(self, other: timedelta) -> Self:
257257
return self._add_timedelta(other)
258258

259259
@overload # type: ignore[override] # this is only needed because of Python 3.7
260-
def __sub__(self, __delta: timedelta) -> Self:
261-
...
260+
def __sub__(self, __delta: timedelta) -> Self: ...
262261

263262
@overload
264-
def __sub__(self, __dt: datetime) -> NoReturn:
265-
...
263+
def __sub__(self, __dt: datetime) -> NoReturn: ...
266264

267265
@overload
268-
def __sub__(self, __dt: Self) -> Interval[Date]:
269-
...
266+
def __sub__(self, __dt: Self) -> Interval[Date]: ...
270267

271268
def __sub__(self, other: timedelta | date) -> Self | Interval[Date]:
272269
if isinstance(other, timedelta):

src/pendulum/datetime.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,11 @@ def instance(
146146

147147
@overload
148148
@classmethod
149-
def now(cls, tz: datetime.tzinfo | None = None) -> Self:
150-
...
149+
def now(cls, tz: datetime.tzinfo | None = None) -> Self: ...
151150

152151
@overload
153152
@classmethod
154-
def now(cls, tz: str | Timezone | FixedTimezone | None = None) -> Self:
155-
...
153+
def now(cls, tz: str | Timezone | FixedTimezone | None = None) -> Self: ...
156154

157155
@classmethod
158156
def now(
@@ -1186,12 +1184,10 @@ def average( # type: ignore[override]
11861184
)
11871185

11881186
@overload # type: ignore[override]
1189-
def __sub__(self, other: datetime.timedelta) -> Self:
1190-
...
1187+
def __sub__(self, other: datetime.timedelta) -> Self: ...
11911188

11921189
@overload
1193-
def __sub__(self, other: DateTime) -> Interval[datetime.datetime]:
1194-
...
1190+
def __sub__(self, other: DateTime) -> Interval[datetime.datetime]: ...
11951191

11961192
def __sub__(
11971193
self, other: datetime.datetime | datetime.timedelta

src/pendulum/duration.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _divide_and_round(a: float, b: float) -> int:
3737
# positive, 2 * r < b if b negative.
3838
r *= 2
3939
greater_than_half = r > b if b > 0 else r < b
40-
if greater_than_half or r == b and q % 2 == 1:
40+
if greater_than_half or (r == b and q % 2 == 1):
4141
q += 1
4242

4343
return q
@@ -375,12 +375,10 @@ def __mul__(self, other: int | float) -> Self:
375375
__rmul__ = __mul__
376376

377377
@overload
378-
def __floordiv__(self, other: timedelta) -> int:
379-
...
378+
def __floordiv__(self, other: timedelta) -> int: ...
380379

381380
@overload
382-
def __floordiv__(self, other: int) -> Self:
383-
...
381+
def __floordiv__(self, other: int) -> Self: ...
384382

385383
def __floordiv__(self, other: int | timedelta) -> int | Duration:
386384
if not isinstance(other, (int, timedelta)):
@@ -389,7 +387,8 @@ def __floordiv__(self, other: int | timedelta) -> int | Duration:
389387
usec = self._to_microseconds()
390388
if isinstance(other, timedelta):
391389
return cast(
392-
int, usec // other._to_microseconds() # type: ignore[attr-defined]
390+
int,
391+
usec // other._to_microseconds(), # type: ignore[attr-defined]
393392
)
394393

395394
if isinstance(other, int):
@@ -402,12 +401,10 @@ def __floordiv__(self, other: int | timedelta) -> int | Duration:
402401
)
403402

404403
@overload
405-
def __truediv__(self, other: timedelta) -> float:
406-
...
404+
def __truediv__(self, other: timedelta) -> float: ...
407405

408406
@overload
409-
def __truediv__(self, other: float) -> Self:
410-
...
407+
def __truediv__(self, other: float) -> Self: ...
411408

412409
def __truediv__(self, other: int | float | timedelta) -> Self | float:
413410
if not isinstance(other, (int, float, timedelta)):
@@ -416,7 +413,8 @@ def __truediv__(self, other: int | float | timedelta) -> Self | float:
416413
usec = self._to_microseconds()
417414
if isinstance(other, timedelta):
418415
return cast(
419-
float, usec / other._to_microseconds() # type: ignore[attr-defined]
416+
float,
417+
usec / other._to_microseconds(), # type: ignore[attr-defined]
420418
)
421419

422420
if isinstance(other, int):
@@ -443,7 +441,7 @@ def __truediv__(self, other: int | float | timedelta) -> Self | float:
443441

444442
def __mod__(self, other: timedelta) -> Self:
445443
if isinstance(other, timedelta):
446-
r = self._to_microseconds() % other._to_microseconds() # type: ignore[attr-defined] # noqa: E501
444+
r = self._to_microseconds() % other._to_microseconds() # type: ignore[attr-defined]
447445

448446
return self.__class__(0, 0, r)
449447

src/pendulum/formatting/formatter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_MATCH_TIMESTAMP = r"[+-]?\d+(\.\d{1,6})?"
3939
_MATCH_WORD = (
4040
"(?i)[0-9]*"
41-
"['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+"
41+
"['a-z\u00a0-\u05ff\u0700-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]+"
4242
r"|[\u0600-\u06FF/]+(\s*?[\u0600-\u06FF]+){1,2}"
4343
)
4444
_MATCH_TIMEZONE = "[A-Za-z0-9-+]+(/[A-Za-z0-9-+_]+)?"

src/pendulum/helpers.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def add_duration(
6262
minutes: int = 0,
6363
seconds: float = 0,
6464
microseconds: int = 0,
65-
) -> _DT:
66-
...
65+
) -> _DT: ...
6766

6867

6968
@overload
@@ -205,17 +204,17 @@ def week_ends_at(wday: WeekDay) -> None:
205204

206205
__all__ = [
207206
"PreciseDiff",
207+
"add_duration",
208208
"days_in_year",
209+
"format_diff",
210+
"get_locale",
209211
"is_leap",
210212
"is_long_year",
211213
"local_time",
212-
"precise_diff",
213-
"week_day",
214-
"add_duration",
215-
"format_diff",
216214
"locale",
215+
"precise_diff",
217216
"set_locale",
218-
"get_locale",
219-
"week_starts_at",
217+
"week_day",
220218
"week_ends_at",
219+
"week_starts_at",
221220
]

0 commit comments

Comments
 (0)