Skip to content

Commit 1d377d8

Browse files
committed
neo4j.api remove indirectly exposed items from imports
1 parent e981cdc commit 1d377d8

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
104104
- `.default_host`
105105
- `.default_port`
106106
- `.default_target`
107-
- `neo4j.graph`, `neo4j.addressing`
107+
- `neo4j.graph`, `neo4j.addressing`, `neo4j.api`
108108
- indirectly exposed items from imports (e.g. `collections.abc.Mapping` as `neo4j.graph.Mapping`).
109109
- Raise `ConfigurationError` instead of ignoring the routing context (URI query parameters) when creating a direct
110110
driver ("bolt[+s[sc]]://" scheme).

src/neo4j/api.py

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@
1616

1717
"""Base classes and helpers."""
1818

19-
from __future__ import annotations
19+
from __future__ import annotations as _
2020

21-
import abc
22-
import typing as t
21+
import abc as _abc
22+
import typing as _t
2323

24+
# ignore TCH001 to make sphinx not completely drop the ball
25+
from ._addressing import Address as _Address # noqa: TCH001
2426

25-
if t.TYPE_CHECKING:
26-
import typing_extensions as te
27+
28+
if _t.TYPE_CHECKING:
29+
import typing_extensions as _te
2730
from typing_extensions import (
28-
deprecated,
31+
deprecated as _deprecated,
2932
Protocol as _Protocol,
3033
)
3134

32-
from ._addressing import Address
35+
3336
else:
34-
from ._warnings import deprecated
37+
from ._warnings import deprecated as _deprecated
3538

3639
_Protocol = object
3740

@@ -61,21 +64,21 @@
6164
]
6265

6366

64-
READ_ACCESS: te.Final[str] = "READ"
65-
WRITE_ACCESS: te.Final[str] = "WRITE"
67+
READ_ACCESS: _te.Final[str] = "READ"
68+
WRITE_ACCESS: _te.Final[str] = "WRITE"
6669

67-
URI_SCHEME_BOLT: te.Final[str] = "bolt"
68-
URI_SCHEME_BOLT_SELF_SIGNED_CERTIFICATE: te.Final[str] = "bolt+ssc"
69-
URI_SCHEME_BOLT_SECURE: te.Final[str] = "bolt+s"
70+
URI_SCHEME_BOLT: _te.Final[str] = "bolt"
71+
URI_SCHEME_BOLT_SELF_SIGNED_CERTIFICATE: _te.Final[str] = "bolt+ssc"
72+
URI_SCHEME_BOLT_SECURE: _te.Final[str] = "bolt+s"
7073

71-
URI_SCHEME_NEO4J: te.Final[str] = "neo4j"
72-
URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE: te.Final[str] = "neo4j+ssc"
73-
URI_SCHEME_NEO4J_SECURE: te.Final[str] = "neo4j+s"
74+
URI_SCHEME_NEO4J: _te.Final[str] = "neo4j"
75+
URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE: _te.Final[str] = "neo4j+ssc"
76+
URI_SCHEME_NEO4J_SECURE: _te.Final[str] = "neo4j+s"
7477

75-
URI_SCHEME_BOLT_ROUTING: te.Final[str] = "bolt+routing"
78+
URI_SCHEME_BOLT_ROUTING: _te.Final[str] = "bolt+routing"
7679

77-
SYSTEM_DATABASE: te.Final[str] = "system"
78-
DEFAULT_DATABASE: te.Final[None] = None # Must be a non string hashable value
80+
SYSTEM_DATABASE: _te.Final[str] = "system"
81+
DEFAULT_DATABASE: _te.Final[None] = None # Must be a non string hashable value
7982

8083

8184
# TODO: This class is not tested
@@ -103,7 +106,7 @@ def __init__(
103106
principal: str | None,
104107
credentials: str | None,
105108
realm: str | None = None,
106-
**parameters: t.Any,
109+
**parameters: _t.Any,
107110
) -> None:
108111
self.scheme = scheme
109112
# Neo4j servers pre 4.4 require the principal field to always be
@@ -117,7 +120,7 @@ def __init__(
117120
if parameters:
118121
self.parameters = parameters
119122

120-
def __eq__(self, other: t.Any) -> bool:
123+
def __eq__(self, other: _t.Any) -> bool:
121124
if not isinstance(other, Auth):
122125
return NotImplemented
123126
return vars(self) == vars(other)
@@ -126,8 +129,8 @@ def __eq__(self, other: t.Any) -> bool:
126129
# For backwards compatibility
127130
AuthToken = Auth
128131

129-
if t.TYPE_CHECKING:
130-
_TAuth: t.TypeAlias = tuple[str, str] | Auth | None
132+
if _t.TYPE_CHECKING:
133+
_TAuth: _t.TypeAlias = tuple[str, str] | Auth | None
131134

132135

133136
def basic_auth(user: str, password: str, realm: str | None = None) -> Auth:
@@ -181,7 +184,7 @@ def custom_auth(
181184
credentials: str | None,
182185
realm: str | None,
183186
scheme: str | None,
184-
**parameters: t.Any,
187+
**parameters: _t.Any,
185188
) -> Auth:
186189
"""
187190
Generate a custom auth token.
@@ -253,7 +256,7 @@ def raw_values(self) -> frozenset[str]:
253256
return self._raw_values
254257

255258
@classmethod
256-
def from_raw_values(cls, values: t.Iterable[str]) -> Bookmarks:
259+
def from_raw_values(cls, values: _t.Iterable[str]) -> Bookmarks:
257260
"""
258261
Create a Bookmarks object from a list of raw bookmark string values.
259262
@@ -286,13 +289,13 @@ def from_raw_values(cls, values: t.Iterable[str]) -> Bookmarks:
286289
class ServerInfo:
287290
"""Represents a package of information relating to a Neo4j server."""
288291

289-
def __init__(self, address: Address, protocol_version: tuple[int, int]):
292+
def __init__(self, address: _Address, protocol_version: tuple[int, int]):
290293
self._address = address
291294
self._protocol_version = protocol_version
292295
self._metadata: dict = {}
293296

294297
@property
295-
def address(self) -> Address:
298+
def address(self) -> _Address:
296299
"""Network address of the remote server."""
297300
return self._address
298301

@@ -312,7 +315,7 @@ def agent(self) -> str:
312315
return str(self._metadata.get("server"))
313316

314317
@property # type: ignore
315-
@deprecated(
318+
@_deprecated(
316319
"The connection id is considered internal information "
317320
"and will no longer be exposed in future versions."
318321
)
@@ -330,7 +333,7 @@ def update(self, metadata: dict) -> None:
330333
self._metadata.update(metadata)
331334

332335

333-
class BookmarkManager(_Protocol, metaclass=abc.ABCMeta):
336+
class BookmarkManager(_Protocol, metaclass=_abc.ABCMeta):
334337
"""
335338
Class to manage bookmarks throughout the driver's lifetime.
336339
@@ -371,11 +374,11 @@ class BookmarkManager(_Protocol, metaclass=abc.ABCMeta):
371374
.. versionchanged:: 5.8 Stabilized from experimental.
372375
"""
373376

374-
@abc.abstractmethod
377+
@_abc.abstractmethod
375378
def update_bookmarks(
376379
self,
377-
previous_bookmarks: t.Collection[str],
378-
new_bookmarks: t.Collection[str],
380+
previous_bookmarks: _t.Collection[str],
381+
new_bookmarks: _t.Collection[str],
379382
) -> None:
380383
"""
381384
Handle bookmark updates.
@@ -387,8 +390,8 @@ def update_bookmarks(
387390
"""
388391
...
389392

390-
@abc.abstractmethod
391-
def get_bookmarks(self) -> t.Collection[str]:
393+
@_abc.abstractmethod
394+
def get_bookmarks(self) -> _t.Collection[str]:
392395
"""
393396
Return the bookmarks stored in the bookmark manager.
394397
@@ -397,7 +400,7 @@ def get_bookmarks(self) -> t.Collection[str]:
397400
...
398401

399402

400-
class AsyncBookmarkManager(_Protocol, metaclass=abc.ABCMeta):
403+
class AsyncBookmarkManager(_Protocol, metaclass=_abc.ABCMeta):
401404
"""
402405
Same as :class:`.BookmarkManager` but with async methods.
403406
@@ -412,16 +415,16 @@ class AsyncBookmarkManager(_Protocol, metaclass=abc.ABCMeta):
412415
.. versionchanged:: 5.8 Stabilized from experimental.
413416
"""
414417

415-
@abc.abstractmethod
418+
@_abc.abstractmethod
416419
async def update_bookmarks(
417420
self,
418-
previous_bookmarks: t.Collection[str],
419-
new_bookmarks: t.Collection[str],
421+
previous_bookmarks: _t.Collection[str],
422+
new_bookmarks: _t.Collection[str],
420423
) -> None: ...
421424

422425
update_bookmarks.__doc__ = BookmarkManager.update_bookmarks.__doc__
423426

424-
@abc.abstractmethod
425-
async def get_bookmarks(self) -> t.Collection[str]: ...
427+
@_abc.abstractmethod
428+
async def get_bookmarks(self) -> _t.Collection[str]: ...
426429

427430
get_bookmarks.__doc__ = BookmarkManager.get_bookmarks.__doc__

0 commit comments

Comments
 (0)