Skip to content

Commit 64112ff

Browse files
authored
Make code compatible with mypy 0.990 (#854)
* remove implicit optional parameters (PEP 484 received an update) * mute metaclass inference limitations of mypy * fix mypy rightfully complaining about empty method bodies * fixed bug in (deprecated) `session.last_bookmark` that mypy uncovered
1 parent b42e7f1 commit 64112ff

21 files changed

+109
-84
lines changed

neo4j/_async/bookmark_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def _bookmarks_to_set(
4545
class AsyncNeo4jBookmarkManager(AsyncBookmarkManager):
4646
def __init__(
4747
self,
48-
initial_bookmarks: t.Mapping[str, t.Union[Bookmarks,
49-
t.Iterable[str]]] = None,
50-
bookmarks_supplier: T_BmSupplier = None,
51-
bookmarks_consumer: T_BmConsumer = None
48+
initial_bookmarks: t.Optional[t.Mapping[str, t.Union[Bookmarks,
49+
t.Iterable[str]]]] = None,
50+
bookmarks_supplier: t.Optional[T_BmSupplier] = None,
51+
bookmarks_consumer: t.Optional[T_BmConsumer] = None
5252
) -> None:
5353
super().__init__()
5454
self._bookmarks_supplier = bookmarks_supplier

neo4j/_async/driver.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import ssl
2828

29+
30+
2931
from .._async_compat.util import AsyncUtil
3032
from .._conf import (
3133
Config,
@@ -218,10 +220,10 @@ def driver(cls, uri, *, auth=None, **config) -> AsyncDriver:
218220
)
219221
def bookmark_manager(
220222
cls,
221-
initial_bookmarks: t.Mapping[str, t.Union[Bookmarks,
222-
t.Iterable[str]]] = None,
223-
bookmarks_supplier: _T_BmSupplier = None,
224-
bookmarks_consumer: _T_BmConsumer = None
223+
initial_bookmarks: t.Optional[t.Mapping[str, t.Union[Bookmarks,
224+
t.Iterable[str]]]] = None,
225+
bookmarks_supplier: t.Optional[_T_BmSupplier] = None,
226+
bookmarks_consumer: t.Optional[_T_BmConsumer] = None
225227
) -> AsyncBookmarkManager:
226228
"""Create a :class:`.AsyncBookmarkManager` with default implementation.
227229

neo4j/_async/work/result.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
if t.TYPE_CHECKING:
2727
import typing_extensions as te
2828

29+
30+
2931
from ..._async_compat.util import AsyncUtil
3032
from ..._codec.hydration import BrokenHydrationObject
3133
from ..._data import (
@@ -517,7 +519,7 @@ async def graph(self) -> Graph:
517519
return self._hydration_scope.get_graph()
518520

519521
async def value(
520-
self, key: _T_ResultKey = 0, default: object = None
522+
self, key: _T_ResultKey = 0, default: t.Optional[object] = None
521523
) -> t.List[t.Any]:
522524
"""Helper function that return the remainder of the result as a list of values.
523525

neo4j/_async/work/session.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
_R = t.TypeVar("_R")
3434
_P = te.ParamSpec("_P")
3535

36+
37+
3638
from ..._async_compat import async_sleep
3739
from ..._async_compat.util import AsyncUtil
3840
from ..._conf import SessionConfig
@@ -236,7 +238,7 @@ def cancel(self) -> None:
236238
async def run(
237239
self,
238240
query: t.Union[str, Query],
239-
parameters: t.Dict[str, t.Any] = None,
241+
parameters: t.Optional[t.Dict[str, t.Any]] = None,
240242
**kwargs: t.Any
241243
) -> AsyncResult:
242244
"""Run a Cypher query within an auto-commit transaction.
@@ -321,7 +323,7 @@ async def last_bookmark(self) -> t.Optional[str]:
321323
if self._auto_result:
322324
await self._auto_result.consume()
323325

324-
if self._transaction and self._transaction._closed:
326+
if self._transaction and self._transaction._closed():
325327
await self._update_bookmark(self._transaction._database,
326328
self._transaction._bookmark)
327329
self._transaction = None
@@ -405,8 +407,8 @@ async def _open_transaction(
405407

406408
async def begin_transaction(
407409
self,
408-
metadata: t.Dict[str, t.Any] = None,
409-
timeout: float = None
410+
metadata: t.Optional[t.Dict[str, t.Any]] = None,
411+
timeout: t.Optional[float] = None
410412
) -> AsyncTransaction:
411413
""" Begin a new unmanaged transaction. Creates a new :class:`.AsyncTransaction` within this session.
412414
At most one transaction may exist in a session at any point in time.

neo4j/_async/work/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def _consume_results(self):
9696
async def run(
9797
self,
9898
query: str,
99-
parameters: t.Dict[str, t.Any] = None,
99+
parameters: t.Optional[t.Dict[str, t.Any]] = None,
100100
**kwparameters: t.Any
101101
) -> AsyncResult:
102102
""" Run a Cypher query within the context of this transaction.

neo4j/_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __getslice__(self, start, stop):
140140
values = tuple(self)[key]
141141
return self.__class__(zip(keys, values))
142142

143-
def get(self, key: str, default: object = None) -> t.Any:
143+
def get(self, key: str, default: t.Optional[object] = None) -> t.Any:
144144
""" Obtain a value from the record by key, returning a default
145145
value if the key does not exist.
146146
@@ -177,7 +177,9 @@ def index(self, key: _T_K) -> int: # type: ignore[override]
177177
else:
178178
raise TypeError(key)
179179

180-
def value(self, key: _T_K = 0, default: object = None) -> t.Any:
180+
def value(
181+
self, key: _T_K = 0, default: t.Optional[object] = None
182+
) -> t.Any:
181183
""" Obtain a single value from the record by index or key. If no
182184
index or key is specified, the first value is returned. If the
183185
specified item does not exist, the default value is returned.

neo4j/_spatial/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,15 @@ class Point(t.Tuple[float, ...]):
4949
#: be interpreted in.
5050
srid: t.Optional[int]
5151

52-
@property
53-
def x(self) -> float:
54-
...
52+
if t.TYPE_CHECKING:
53+
@property
54+
def x(self) -> float: ...
5555

56-
@property
57-
def y(self) -> float:
58-
...
56+
@property
57+
def y(self) -> float: ...
5958

60-
@property
61-
def z(self) -> float:
62-
...
59+
@property
60+
def z(self) -> float: ...
6361

6462
def __new__(cls, iterable: t.Iterable[float]) -> Point:
6563
return tuple.__new__(cls, map(float, iterable))

neo4j/_sync/bookmark_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def _bookmarks_to_set(
4545
class Neo4jBookmarkManager(BookmarkManager):
4646
def __init__(
4747
self,
48-
initial_bookmarks: t.Mapping[str, t.Union[Bookmarks,
49-
t.Iterable[str]]] = None,
50-
bookmarks_supplier: T_BmSupplier = None,
51-
bookmarks_consumer: T_BmConsumer = None
48+
initial_bookmarks: t.Optional[t.Mapping[str, t.Union[Bookmarks,
49+
t.Iterable[str]]]] = None,
50+
bookmarks_supplier: t.Optional[T_BmSupplier] = None,
51+
bookmarks_consumer: t.Optional[T_BmConsumer] = None
5252
) -> None:
5353
super().__init__()
5454
self._bookmarks_supplier = bookmarks_supplier

neo4j/_sync/driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ def driver(cls, uri, *, auth=None, **config) -> Driver:
217217
)
218218
def bookmark_manager(
219219
cls,
220-
initial_bookmarks: t.Mapping[str, t.Union[Bookmarks,
221-
t.Iterable[str]]] = None,
222-
bookmarks_supplier: _T_BmSupplier = None,
223-
bookmarks_consumer: _T_BmConsumer = None
220+
initial_bookmarks: t.Optional[t.Mapping[str, t.Union[Bookmarks,
221+
t.Iterable[str]]]] = None,
222+
bookmarks_supplier: t.Optional[_T_BmSupplier] = None,
223+
bookmarks_consumer: t.Optional[_T_BmConsumer] = None
224224
) -> BookmarkManager:
225225
"""Create a :class:`.BookmarkManager` with default implementation.
226226

neo4j/_sync/work/result.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
if t.TYPE_CHECKING:
2727
import typing_extensions as te
2828

29+
30+
2931
from ..._async_compat.util import Util
3032
from ..._codec.hydration import BrokenHydrationObject
3133
from ..._data import (
@@ -517,7 +519,7 @@ def graph(self) -> Graph:
517519
return self._hydration_scope.get_graph()
518520

519521
def value(
520-
self, key: _T_ResultKey = 0, default: object = None
522+
self, key: _T_ResultKey = 0, default: t.Optional[object] = None
521523
) -> t.List[t.Any]:
522524
"""Helper function that return the remainder of the result as a list of values.
523525

0 commit comments

Comments
 (0)