Skip to content

Commit 8367b44

Browse files
committed
Clean-up: lift code base to Python 3.10
1 parent 350ab31 commit 8367b44

Some content is hidden

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

48 files changed

+448
-370
lines changed

benchkit/workloads.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import enum
2121
import typing as t
2222
from dataclasses import dataclass
23-
from typing import Iterator
2423

2524
import typing_extensions as te
2625

2726

2827
if t.TYPE_CHECKING:
28+
from collections.abc import Iterator
29+
2930
from neo4j import (
3031
AsyncDriver,
3132
AsyncManagedTransaction,

bin/make-unasync

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class CustomRule(unasync.Rule):
113113
# it's not pretty, but it works
114114
# typing.Awaitable[...] -> typing.Union[...]
115115
self.token_replacements["Awaitable"] = "Union"
116+
self.token_replacements["aiter"] = "iter"
117+
self.token_replacements["anext"] = "next"
116118

117119
def _unasync_tokens(self, tokens):
118120
# copy from unasync to fix handling of multiline strings
@@ -300,16 +302,15 @@ def apply_isort(paths):
300302

301303
def apply_changes(paths):
302304
def files_equal(path1, path2):
303-
with open(path1, "rb") as f1:
304-
with open(path2, "rb") as f2:
305+
with open(path1, "rb") as f1, open(path2, "rb") as f2:
306+
data1 = f1.read(1024)
307+
data2 = f2.read(1024)
308+
while data1 or data2:
309+
if data1 != data2:
310+
changed_paths[path1] = path2
311+
return False
305312
data1 = f1.read(1024)
306313
data2 = f2.read(1024)
307-
while data1 or data2:
308-
if data1 != data2:
309-
changed_paths[path1] = path2
310-
return False
311-
data1 = f1.read(1024)
312-
data2 = f2.read(1024)
313314
return True
314315

315316
changed_paths = {}

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ extend-exclude = [
144144
preview = true # to get CPY lints
145145
extend-ignore = [
146146
"RUF002", # allow ’ (RIGHT SINGLE QUOTATION MARK) to be used as an apostrophe (e.g. "it’s")
147-
"SIM117", # TODO: when Python 3.10+ is the minimum,
148-
# we can start to use multi-item `with` statements
147+
149148
# pydocstyle
150149
"D1", # disable check for undocumented items (way too noisy)
151150
"D203", # `one-blank-line-before-class`
@@ -195,6 +194,9 @@ extend-ignore = [
195194
# needs fixing in ruff to work with typing.Protocol
196195
# https://github.com/astral-sh/ruff/issues/13307
197196
"FURB180",
197+
198+
# rule is deprected and suggests not recommended practice
199+
"UP038",
198200
]
199201
select = [
200202
# ruff

src/neo4j/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def __getattr__(name) -> _t.Any:
225225
raise AttributeError(f"module {__name__} has no attribute {name}")
226226

227227

228-
def __dir__() -> _t.List[str]:
228+
def __dir__() -> list[str]:
229229
return __all__
230230

231231

src/neo4j/_api.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ class NotificationMinimumSeverity(str, Enum):
6767

6868

6969
if t.TYPE_CHECKING:
70-
T_NotificationMinimumSeverity = t.Union[
71-
NotificationMinimumSeverity,
72-
te.Literal[
70+
T_NotificationMinimumSeverity = (
71+
NotificationMinimumSeverity
72+
| te.Literal[
7373
"OFF",
7474
"WARNING",
7575
"INFORMATION",
76-
],
77-
]
76+
]
77+
)
7878
__all__.append("T_NotificationMinimumSeverity")
7979

8080

@@ -213,10 +213,10 @@ class NotificationDisabledClassification(str, Enum):
213213

214214

215215
if t.TYPE_CHECKING:
216-
T_NotificationDisabledCategory = t.Union[
217-
NotificationDisabledCategory,
218-
NotificationDisabledClassification,
219-
te.Literal[
216+
T_NotificationDisabledCategory = (
217+
NotificationDisabledCategory
218+
| NotificationDisabledClassification
219+
| te.Literal[
220220
"HINT",
221221
"UNRECOGNIZED",
222222
"UNSUPPORTED",
@@ -226,8 +226,8 @@ class NotificationDisabledClassification(str, Enum):
226226
"SECURITY",
227227
"TOPOLOGY",
228228
"SCHEMA",
229-
],
230-
]
229+
]
230+
)
231231
__all__.append("T_NotificationDisabledCategory")
232232

233233

@@ -343,8 +343,5 @@ class TelemetryAPI(int, Enum):
343343

344344

345345
if t.TYPE_CHECKING:
346-
T_RoutingControl = t.Union[
347-
RoutingControl,
348-
te.Literal["r", "w"],
349-
]
346+
T_RoutingControl = RoutingControl | te.Literal["r", "w"]
350347
__all__.append("T_RoutingControl")

src/neo4j/_async/_debug/_concurrency_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def inner(*args, **kwargs):
129129
tbs = deepcopy(self.__tracebacks)
130130
if acquired:
131131
try:
132-
item = await iter_.__anext__()
132+
item = await anext(iter_)
133133
except StopAsyncIteration:
134134
return
135135
finally:

src/neo4j/_async/bookmark_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
)
2727

2828

29-
TBmSupplier = t.Callable[[], t.Union[Bookmarks, t.Awaitable[Bookmarks]]]
30-
TBmConsumer = t.Callable[[Bookmarks], t.Union[None, t.Awaitable[None]]]
29+
TBmSupplier = t.Callable[[], Bookmarks | t.Awaitable[Bookmarks]]
30+
TBmConsumer = t.Callable[[Bookmarks], None | t.Awaitable[None]]
3131

3232

3333
def _bookmarks_to_set(

src/neo4j/_async/home_db_cache.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@
2828
if t.TYPE_CHECKING:
2929
import typing_extensions as te
3030

31-
TKey: te.TypeAlias = t.Union[
32-
str,
33-
t.Tuple[t.Tuple[str, t.Hashable], ...],
34-
t.Tuple[None],
35-
]
36-
TVal: te.TypeAlias = t.Tuple[float, str]
31+
TKey: te.TypeAlias = str | tuple[tuple[str, t.Hashable], ...] | tuple[None]
32+
TVal: te.TypeAlias = tuple[float, str]
3733

3834

3935
class AsyncHomeDbCache:

src/neo4j/_async/io/_bolt3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ async def route(
309309
await self.send_all()
310310
await self.fetch_all()
311311
return [
312-
dict(zip(metadata.get("fields", ()), values)) for values in records
312+
dict(zip(metadata.get("fields", ()), values, strict=False))
313+
for values in records
313314
]
314315

315316
def run(

src/neo4j/_async/io/_bolt4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ async def route(
224224
await self.send_all()
225225
await self.fetch_all()
226226
return [
227-
dict(zip(metadata.get("fields", ()), values)) for values in records
227+
dict(zip(metadata.get("fields", ()), values, strict=False))
228+
for values in records
228229
]
229230

230231
def run(

0 commit comments

Comments
 (0)