Skip to content

Commit d3fb09d

Browse files
authored
Bump pre-commit hooks & fix new lints (#1204)
1 parent 96776d3 commit d3fb09d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+96
-87
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.1.0
5+
rev: v5.0.0
66
hooks:
77
- id: check-case-conflict
88
- id: check-docstring-first
@@ -27,14 +27,14 @@ repos:
2727
types_or: [ python, pyi ]
2828
language: system
2929
- repo: https://github.com/sphinx-contrib/sphinx-lint
30-
rev: e83a1a42a73284d301c05baaffc176042ffbcf82
30+
rev: ff671d6a030a3141634793e6d1e8909ab6091830
3131
hooks:
3232
- id: sphinx-lint
3333
- repo: https://github.com/astral-sh/ruff-pre-commit
34-
rev: v0.6.4
34+
rev: v0.11.12
3535
hooks:
3636
- id: ruff-format
37-
- id: ruff
37+
- id: ruff-check
3838
args: [ --fix ]
3939
- id: ruff-format
4040
- repo: local

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ extend-ignore = [
266266
"RET507",
267267
"RET508",
268268

269+
# prefer to not use forward references in typing.cast calls
270+
# (worse IDE support => worse DX)
271+
"TC006",
272+
269273
"PERF203", # try-except within loop is fine. Especially in a retry scenario
270274

271275
# too noisy and opinionated FURB lints
@@ -329,7 +333,7 @@ select = [
329333
# check return statements
330334
"RET",
331335
# check type-checking usage
332-
"TCH",
336+
"TC",
333337
# copyright notice
334338
"CPY",
335339
# check shebangs
@@ -349,6 +353,7 @@ select = [
349353
]
350354
"tests/integration/examples/**" = [
351355
"T20", # print statements are part of the examples
356+
"LOG015", # examples are simplified => they may use non-polished logging calls
352357
]
353358
"tests/unit/**" = [
354359
"PLW1641", # no need for production grade test code
@@ -376,3 +381,6 @@ notice-rgx = "# Copyright \\(c\\) \"Neo4j\""
376381

377382
[tool.ruff.lint.pydocstyle]
378383
convention = "pep257"
384+
385+
[tool.ruff.lint.flake8-pytest-style]
386+
warns-extend-require-match-for = ["neo4j.warning.PreviewWarning"]

src/neo4j/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@
7676

7777

7878
if _t.TYPE_CHECKING:
79-
from ._api import NotificationDisabledClassification # noqa: TCH004 false positive (dynamic attribute)
79+
from ._api import NotificationDisabledClassification
8080
from ._work import (
81-
GqlStatusObject, # noqa: TCH004 false positive (dynamic attribute)
82-
NotificationClassification, # noqa: TCH004 false positive (dynamic attribute)
81+
GqlStatusObject,
82+
NotificationClassification,
8383
)
84-
from ._warnings import PreviewWarning # noqa: TCH004 false positive (dynamic attribute)
84+
from ._warnings import PreviewWarning
8585

8686
from ._addressing import (
8787
Address,

src/neo4j/_async/auth_management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
ExpiringAuth,
3333
)
3434

35-
# ignore TCH001 to make sphinx not completely drop the ball
36-
from ..api import _TAuth # noqa: TCH001
35+
# ignore TC001 to make sphinx not completely drop the ball
36+
from ..api import _TAuth # noqa: TC001
3737

3838

3939
if t.TYPE_CHECKING:

src/neo4j/_async/bookmark_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
TBmSupplier = t.Callable[[], Bookmarks | t.Awaitable[Bookmarks]]
29-
TBmConsumer = t.Callable[[Bookmarks], None | t.Awaitable[None]]
29+
TBmConsumer = t.Callable[[Bookmarks], t.Awaitable[None] | None]
3030

3131

3232
class AsyncNeo4jBookmarkManager(AsyncBookmarkManager):

src/neo4j/_async/driver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ def session(self, **config) -> AsyncSession:
573573
.. versionchanged:: 6.0
574574
Raise :exc:`DriverError` if the driver has been closed.
575575
"""
576-
if "warn_notification_severity" in config:
577-
# Would work just fine, but we don't want to introduce yet
578-
# another undocumented/unsupported config option.
579-
del config["warn_notification_severity"]
576+
# Would work just fine, but we don't want to introduce yet
577+
# another undocumented/unsupported config option.
578+
config.pop("warn_notification_severity", None)
579+
580580
self._check_state()
581581
if "notifications_disabled_classifications" in config:
582582
preview_warn(
@@ -663,8 +663,8 @@ async def execute_query(
663663
bookmark_manager_: (
664664
AsyncBookmarkManager
665665
| BookmarkManager
666-
| None
667666
| t.Literal[_DefaultEnum.default]
667+
| None
668668
) = _default,
669669
auth_: _TAuth = None,
670670
result_transformer_: t.Callable[

src/neo4j/_async/io/_bolt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def tx_timeout_as_ms(timeout: float) -> int:
10531053
raise err_type(msg) from None
10541054
if timeout < 0:
10551055
raise ValueError("Timeout must be a positive number or 0.")
1056-
ms = int(round(1000 * timeout))
1056+
ms = round(1000 * timeout)
10571057
if ms == 0 and timeout > 0:
10581058
# Special case for 0 < timeout < 0.5 ms.
10591059
# This would be rounded to 0 ms, but the server interprets this as

src/neo4j/_async/io/_bolt_socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def _parse_handshake_response_v2(
9595
offering = offering_response[-1:-4:-1]
9696
offerings.append(offering)
9797
ctx.ctx = "handshake v2 capabilities"
98-
_capabilities_offer = await self._read_varint(ctx)
98+
capabilities_offer = await self._read_varint(ctx)
9999

100100
if log.getEffectiveLevel() <= logging.DEBUG:
101101
log.debug(
@@ -106,7 +106,7 @@ async def _parse_handshake_response_v2(
106106
" ".join(
107107
f"0x{vx[2]:04X}{vx[1]:02X}{vx[0]:02X}" for vx in offerings
108108
),
109-
BytesPrinter(self._encode_varint(_capabilities_offer)),
109+
BytesPrinter(self._encode_varint(capabilities_offer)),
110110
)
111111

112112
supported_versions = sorted(self.Bolt.protocol_handlers.keys())

src/neo4j/_async/io/_pool.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ async def _re_auth_connection(self, connection, auth, force, unprepared):
300300
)
301301
except Exception as exc:
302302
log.debug(
303-
"[#%04X] _: <POOL> check re_auth failed %r auth=%s "
304-
"force=%s",
303+
"[#%04X] _: <POOL> check re_auth failed %r auth=%s force=%s",
305304
connection.local_port,
306305
exc,
307306
log_auth,
@@ -881,8 +880,7 @@ async def fetch_routing_table(
881880
# No readers
882881
if num_readers == 0:
883882
log.debug(
884-
"[#0000] _: <POOL> no read servers returned from "
885-
"server %s",
883+
"[#0000] _: <POOL> no read servers returned from server %s",
886884
address,
887885
)
888886
return None

src/neo4j/_async/work/result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class AsyncResult(AsyncNonConcurrentMethodChecker):
101101
"""
102102

103103
_creation_stack: list[inspect.FrameInfo] | None
104-
_creation_frame_cache: None | t.Literal[False] | inspect.FrameInfo
104+
_creation_frame_cache: t.Literal[False] | inspect.FrameInfo | None
105105

106106
def __init__(
107107
self,

src/neo4j/_async/work/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import asyncio
2020

21-
from ... import _typing as t # noqa: TCH001
21+
from ... import _typing as t # noqa: TC001
2222
from ..._async_compat.util import AsyncUtil
2323
from ..._work import Query
2424
from ...exceptions import TransactionError

src/neo4j/_async_compat/concurrency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
import threading
2323

24-
from .. import _typing as t # noqa: TCH001
24+
from .. import _typing as t # noqa: TC001
2525
from .shims import wait_for
2626

2727

src/neo4j/_auth_management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import time
2121
from dataclasses import dataclass
2222

23-
# ignore TCH003 to make sphinx not completely drop the ball
24-
from os import PathLike # noqa: TCH003
23+
# ignore TC003 to make sphinx not completely drop the ball
24+
from os import PathLike # noqa: TC003
2525

2626
from . import _typing as t
2727
from .api import (

src/neo4j/_codec/hydration/v1/temporal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ def dehydrate_np_datetime(value):
221221
# while we could encode years outside the range, they would fail
222222
# when retrieved from the database.
223223
raise ValueError(
224-
f"Year out of range ({MIN_YEAR:d}..{MAX_YEAR:d}) "
225-
f"found {year}"
224+
f"Year out of range ({MIN_YEAR:d}..{MAX_YEAR:d}) found {year}"
226225
)
227226
seconds = value.astype(np.dtype("datetime64[s]")).astype(int)
228227
nanoseconds = (

src/neo4j/_debug/_notification_printer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def __str__(self):
5050
if pos.line <= 0 or pos.line > len(query_lines) or pos.column <= 0:
5151
return s + self.query
5252
query_lines = (
53-
query_lines[: pos.line]
54-
+ [" " * (pos.column - 1) + "^"]
55-
+ query_lines[pos.line :]
53+
*query_lines[: pos.line],
54+
" " * (pos.column - 1) + "^",
55+
*query_lines[pos.line :],
5656
)
5757
s += "\n".join(query_lines)
5858
return s

src/neo4j/_io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from __future__ import annotations
1818

19-
from .. import _typing as t # noqa: TCH001
19+
from .. import _typing as t # noqa: TC001
2020

2121

2222
__all__ = [

src/neo4j/_meta.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def format_version_info(version_info):
6262

6363
def _compute_user_agent() -> str:
6464
return (
65-
f'{BOLT_AGENT_DICT["product"]} '
66-
f'{BOLT_AGENT_DICT["language"]} '
67-
f'({sys.platform})'
65+
f"{BOLT_AGENT_DICT['product']} "
66+
f"{BOLT_AGENT_DICT['language']} "
67+
f"({sys.platform})"
6868
)
6969

7070

src/neo4j/_optional_deps/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from contextlib import suppress
2020

21-
from .. import _typing as t # noqa: TCH001
21+
from .. import _typing as t # noqa: TC001
2222

2323

2424
np: t.Any = None

src/neo4j/_sync/auth_management.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/bookmark_manager.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/driver.py

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/io/_bolt.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/io/_bolt_socket.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/io/_pool.py

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/work/result.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_sync/work/transaction.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/_typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
)
9191

9292
if TYPE_CHECKING:
93-
from typing_extensions import NotRequired # Python 3.11+ # noqa: TCH004
94-
from typing_extensions import Self # Python 3.11 # noqa: TCH004
95-
from typing_extensions import ( # Python 3.11 # noqa: TCH004 Python
93+
from typing_extensions import NotRequired # Python 3.11+ # noqa: TC004
94+
from typing_extensions import Self # Python 3.11 # noqa: TC004
95+
from typing_extensions import ( # Python 3.11 # noqa: TC004 Python
9696
LiteralString,
9797
)
9898

src/neo4j/_work/summary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import itertools
2020
import typing as t
2121

22-
# ignore TCH003 to make sphinx not completely drop the ball
23-
from collections.abc import Sequence # noqa: TCH003
22+
# ignore TC003 to make sphinx not completely drop the ball
23+
from collections.abc import Sequence # noqa: TC003
2424
from copy import deepcopy
2525
from dataclasses import dataclass
2626

0 commit comments

Comments
 (0)