Skip to content

Commit 54e8bb0

Browse files
committed
neo4j.graph remove indirectly exposed items from imports
1 parent 410f0bf commit 54e8bb0

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
7474
- Remove `ExperimentalWarning` and turn the few left instances of it into `PreviewWarning`.
7575
- Deprecate importing `PreviewWarning` from `neo4j`.
7676
Import it from `neo4j.warnings` instead.
77-
- Make undocumented internal constants and helper functions private:
77+
- Make undocumented internal constants, helper functions, and other items private:
7878
- `neo4j.api`
7979
- `DRIVER_BOLT`
8080
- `DRIVER_NEO4J`
@@ -104,6 +104,8 @@ 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`
108+
- indirectly exposed items from imports (e.g. `collections.abc.Mapping` as `neo4j.graph.Mapping`).
107109
- Raise `ConfigurationError` instead of ignoring the routing context (URI query parameters) when creating a direct
108110
driver ("bolt[+s[sc]]://" scheme).
109111
- Change behavior of closed drivers:

src/neo4j/graph/__init__.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
"""Graph data types as returned by the DBMS."""
1818

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

21-
import typing as t
22-
from collections.abc import Mapping
21+
import typing as _t
22+
from collections.abc import Mapping as _Mapping
2323

2424

25-
if t.TYPE_CHECKING:
26-
from typing_extensions import deprecated
25+
if _t.TYPE_CHECKING:
26+
from typing_extensions import deprecated as _deprecated
2727
else:
28-
from .._warnings import deprecated
28+
from .._warnings import deprecated as _deprecated
2929

3030

3131
__all__ = [
@@ -36,7 +36,7 @@
3636
]
3737

3838

39-
_T = t.TypeVar("_T")
39+
_T = _t.TypeVar("_T")
4040

4141

4242
class Graph:
@@ -71,7 +71,7 @@ def relationship_type(self, name: str) -> type[Relationship]:
7171
try:
7272
cls = self._relationship_types[name]
7373
except KeyError:
74-
cls = self._relationship_types[name] = t.cast(
74+
cls = self._relationship_types[name] = _t.cast(
7575
type[Relationship], type(str(name), (Relationship,), {})
7676
)
7777
return cls
@@ -92,7 +92,7 @@ def _restore(relationship_types: tuple[str, ...]) -> Graph:
9292
return graph
9393

9494

95-
class Entity(t.Mapping[str, t.Any]):
95+
class Entity(_t.Mapping[str, _t.Any]):
9696
"""
9797
Graph entity base.
9898
@@ -106,7 +106,7 @@ def __init__(
106106
graph: Graph,
107107
element_id: str,
108108
id_: int,
109-
properties: dict[str, t.Any] | None,
109+
properties: dict[str, _t.Any] | None,
110110
) -> None:
111111
self._graph = graph
112112
self._element_id = element_id
@@ -115,7 +115,7 @@ def __init__(
115115
k: v for k, v in (properties or {}).items() if v is not None
116116
}
117117

118-
def __eq__(self, other: t.Any) -> bool:
118+
def __eq__(self, other: _t.Any) -> bool:
119119
# TODO: 6.0 - return NotImplemented on type mismatch instead of False
120120
try:
121121
return (
@@ -135,13 +135,13 @@ def __hash__(self):
135135
def __len__(self) -> int:
136136
return len(self._properties)
137137

138-
def __getitem__(self, name: str) -> t.Any:
138+
def __getitem__(self, name: str) -> _t.Any:
139139
return self._properties.get(name)
140140

141141
def __contains__(self, name: object) -> bool:
142142
return name in self._properties
143143

144-
def __iter__(self) -> t.Iterator[str]:
144+
def __iter__(self) -> _t.Iterator[str]:
145145
return iter(self._properties)
146146

147147
@property
@@ -150,7 +150,7 @@ def graph(self) -> Graph:
150150
return self._graph
151151

152152
@property # type: ignore
153-
@deprecated("`id` is deprecated, use `element_id` instead")
153+
@_deprecated("`id` is deprecated, use `element_id` instead")
154154
def id(self) -> int:
155155
"""
156156
The legacy identity of this entity in its container :class:`.Graph`.
@@ -182,24 +182,24 @@ def element_id(self) -> str:
182182
"""
183183
return self._element_id
184184

185-
def get(self, name: str, default: object = None) -> t.Any:
185+
def get(self, name: str, default: object = None) -> _t.Any:
186186
"""Get a property value by name, optionally with a default."""
187187
return self._properties.get(name, default)
188188

189-
def keys(self) -> t.KeysView[str]:
189+
def keys(self) -> _t.KeysView[str]:
190190
"""Return an iterable of all property names."""
191191
return self._properties.keys()
192192

193-
def values(self) -> t.ValuesView[t.Any]:
193+
def values(self) -> _t.ValuesView[_t.Any]:
194194
"""Return an iterable of all property values."""
195195
return self._properties.values()
196196

197-
def items(self) -> t.ItemsView[str, t.Any]:
197+
def items(self) -> _t.ItemsView[str, _t.Any]:
198198
"""Return an iterable of all property name-value pairs."""
199199
return self._properties.items()
200200

201201

202-
class EntitySetView(Mapping, t.Generic[_T]):
202+
class EntitySetView(_Mapping, _t.Generic[_T]):
203203
"""View of a set of :class:`.Entity` instances within a :class:`.Graph`."""
204204

205205
def __init__(
@@ -214,7 +214,7 @@ def __getitem__(self, e_id: str) -> _T:
214214
def __len__(self) -> int:
215215
return len(self._entity_dict)
216216

217-
def __iter__(self) -> t.Iterator[_T]:
217+
def __iter__(self) -> _t.Iterator[_T]:
218218
return iter(self._entity_dict.values())
219219

220220

@@ -226,8 +226,8 @@ def __init__(
226226
graph: Graph,
227227
element_id: str,
228228
id_: int,
229-
n_labels: t.Iterable[str] | None = None,
230-
properties: dict[str, t.Any] | None = None,
229+
n_labels: _t.Iterable[str] | None = None,
230+
properties: dict[str, _t.Any] | None = None,
231231
) -> None:
232232
Entity.__init__(self, graph, element_id, id_, properties)
233233
self._labels = frozenset(n_labels or ())
@@ -252,7 +252,7 @@ def __init__(
252252
graph: Graph,
253253
element_id: str,
254254
id_: int,
255-
properties: dict[str, t.Any],
255+
properties: dict[str, _t.Any],
256256
) -> None:
257257
Entity.__init__(self, graph, element_id, id_, properties)
258258
self._start_node: Node | None = None
@@ -307,9 +307,9 @@ def __init__(self, start_node: Node, *relationships: Relationship) -> None:
307307
for i, relationship in enumerate(relationships, start=1):
308308
assert isinstance(relationship, Relationship)
309309
if relationship.start_node == nodes[-1]:
310-
nodes.append(t.cast(Node, relationship.end_node))
310+
nodes.append(_t.cast(Node, relationship.end_node))
311311
elif relationship.end_node == nodes[-1]:
312-
nodes.append(t.cast(Node, relationship.start_node))
312+
nodes.append(_t.cast(Node, relationship.start_node))
313313
else:
314314
raise ValueError(
315315
f"Relationship {i} does not connect to the last node"
@@ -323,7 +323,7 @@ def __repr__(self) -> str:
323323
f"size={len(self)}>"
324324
)
325325

326-
def __eq__(self, other: t.Any) -> bool:
326+
def __eq__(self, other: _t.Any) -> bool:
327327
# TODO: 6.0 - return NotImplemented on type mismatch instead of False
328328
try:
329329
return (
@@ -345,7 +345,7 @@ def __hash__(self):
345345
def __len__(self) -> int:
346346
return len(self._relationships)
347347

348-
def __iter__(self) -> t.Iterator[Relationship]:
348+
def __iter__(self) -> _t.Iterator[Relationship]:
349349
return iter(self._relationships)
350350

351351
@property

0 commit comments

Comments
 (0)