Skip to content

Commit b69967a

Browse files
committed
Update ruff config, use ruff format instead of black
1 parent 09d815a commit b69967a

File tree

17 files changed

+117
-148
lines changed

17 files changed

+117
-148
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 7 deletions
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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,47 +90,52 @@ test = ["time-machine"]
9090
[tool.maturin]
9191
module-name = "pendulum._pendulum"
9292

93-
9493
[tool.ruff]
9594
fix = true
96-
unfixable = [
97-
"ERA", # do not autoremove commented out code
98-
]
99-
target-version = "py38"
10095
line-length = 88
96+
target-version = "py38"
97+
extend-exclude = [
98+
# External to the project's coding standards:
99+
"docs/*",
100+
# Machine-generated, too many false-positives
101+
"src/pendulum/locales/*",
102+
# ruff disagrees with black when it comes to formatting
103+
"*.pyi",
104+
]
105+
106+
[tool.ruff.lint]
101107
extend-select = [
102-
"B", # flake8-bugbear
103-
"C4", # flake8-comprehensions
108+
"B", # flake8-bugbear
109+
"C4", # flake8-comprehensions
104110
"ERA", # flake8-eradicate/eradicate
105-
"I", # isort
106-
"N", # pep8-naming
111+
"I", # isort
112+
"N", # pep8-naming
107113
"PIE", # flake8-pie
108114
"PGH", # pygrep
109115
"RUF", # ruff checks
110116
"SIM", # flake8-simplify
117+
"T20", # flake8-print
111118
"TCH", # flake8-type-checking
112119
"TID", # flake8-tidy-imports
113-
"UP", # pyupgrade
120+
"UP", # pyupgrade
114121
]
115122
ignore = [
116123
"B904", # use 'raise ... from err'
117124
"B905", # use explicit 'strict=' parameter with 'zip()'
118-
"N818", # Exception name should be named with an Error suffix
119-
"RUF001",
125+
"N818",
126+
"RUF001"
120127
]
121-
extend-exclude = [
122-
# External to the project's coding standards:
123-
"docs/*",
124-
# Machine-generated, too many false-positives
125-
"src/pendulum/locales/*",
126-
# ruff disagrees with black when it comes to formatting
127-
"*.pyi",
128+
extend-safe-fixes = [
129+
"TCH", # move import from and to TYPE_CHECKING blocks
130+
]
131+
unfixable = [
132+
"ERA", # do not autoremove commented out code
128133
]
129134

130-
[tool.ruff.flake8-tidy-imports]
135+
[tool.ruff.lint.flake8-tidy-imports]
131136
ban-relative-imports = "all"
132137

133-
[tool.ruff.isort]
138+
[tool.ruff.lint.isort]
134139
force-single-line = true
135140
lines-between-types = 1
136141
lines-after-imports = 2

src/pendulum/__init__.py

Lines changed: 16 additions & 22 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ def precise_diff(
175175
)
176176

177177
if (
178-
tzinfo1 is None
179-
and tzinfo2 is not None
180-
or tzinfo2 is None
181-
and tzinfo1 is not None
178+
(tzinfo1 is None
179+
and tzinfo2 is not None)
180+
or (tzinfo2 is None
181+
and tzinfo1 is not None)
182182
):
183183
raise ValueError(
184184
"Comparison between naive and aware datetimes is not supported"

src/pendulum/date.py

Lines changed: 3 additions & 6 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 10 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 8 deletions
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)