Skip to content

Commit a362608

Browse files
Mark internals in driver.py with underscore (#1181)
Rename undocumented internals to have a leading `_` * `GraphDatabase` * `.bolt_driver` *`.neo4j_driver` * `BoltDriver` and `Neo4jDriver` * `.open` * `.parse_target` * `.default_host` * `.default_port` * `.default_target` Signed-off-by: Rouven Bauer <rouven.bauer@neo4j.com> Co-authored-by: Steve Cathcart <stephen.cathcart@neotechnology.com>
1 parent e6a2efc commit a362608

File tree

4 files changed

+63
-76
lines changed

4 files changed

+63
-76
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
9191
- `ERROR_REWRITE_MAP`
9292
- `client_errors`
9393
- `transient_errors`
94+
- `GraphDatabase`
95+
- `.bolt_driver`
96+
- `.neo4j_driver`
97+
- `BoltDriver` and `Neo4jDriver`
98+
- `.open`
99+
- `.parse_target`
100+
- `.default_host`
101+
- `.default_port`
102+
- `.default_target`
94103
- Raise `ConfigurationError` instead of ignoring the routing context (URI query parameters) when creating a direct
95104
driver ("bolt[+s[sc]]://" scheme).
96105
- Change behavior of closed drivers:

src/neo4j/_async/driver.py

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
)
5252
from .._debug import ENABLED as DEBUG_ENABLED
5353
from .._warnings import (
54-
deprecation_warn,
5554
preview_warn,
5655
unclosed_resource_warn,
5756
)
@@ -284,10 +283,10 @@ def driver(
284283
"supported by direct drivers "
285284
f'("bolt[+s[sc]]://" scheme). Given URI: {uri!r}.'
286285
)
287-
return cls.bolt_driver(parsed.netloc, **config)
286+
return cls._bolt_driver(parsed.netloc, **config)
288287
# else driver_type == DRIVER_NEO4J
289288
routing_context = parse_routing_context(parsed.query)
290-
return cls.neo4j_driver(
289+
return cls._neo4j_driver(
291290
parsed.netloc, routing_context=routing_context, **config
292291
)
293292

@@ -376,7 +375,7 @@ def bookmark_manager(
376375
)
377376

378377
@classmethod
379-
def bolt_driver(cls, target, **config):
378+
def _bolt_driver(cls, target, **config):
380379
"""
381380
Create a direct driver.
382381
@@ -389,36 +388,28 @@ def bolt_driver(cls, target, **config):
389388
)
390389

391390
try:
392-
return AsyncBoltDriver.open(target, **config)
391+
return AsyncBoltDriver._open(target, **config)
393392
except (BoltHandshakeError, BoltSecurityError) as error:
394393
from ..exceptions import ServiceUnavailable
395394

396395
raise ServiceUnavailable(str(error)) from error
397396

398397
@classmethod
399-
def neo4j_driver(cls, *targets, routing_context=None, **config):
398+
def _neo4j_driver(cls, target, routing_context=None, **config):
400399
"""
401400
Create a routing driver.
402401
403402
Create a driver for routing-capable Neo4j service access
404403
that uses socket I/O and thread-based concurrency.
405404
"""
406-
# TODO: 6.0 - adjust signature to only take one target
407-
if len(targets) > 1:
408-
deprecation_warn(
409-
"Creating a routing driver with multiple targets is "
410-
"deprecated. The driver only uses the first target anyway. "
411-
"The method signature will change in a future release.",
412-
)
413-
414405
from .._exceptions import (
415406
BoltHandshakeError,
416407
BoltSecurityError,
417408
)
418409

419410
try:
420-
return AsyncNeo4jDriver.open(
421-
*targets, routing_context=routing_context, **config
411+
return AsyncNeo4jDriver._open(
412+
target, routing_context=routing_context, **config
422413
)
423414
except (BoltHandshakeError, BoltSecurityError) as error:
424415
from ..exceptions import ServiceUnavailable
@@ -427,10 +418,9 @@ def neo4j_driver(cls, *targets, routing_context=None, **config):
427418

428419

429420
class _Direct:
430-
# TODO: 6.0 - those attributes should be private
431-
default_host = "localhost"
432-
default_port = 7687
433-
default_target = ":"
421+
_default_host = "localhost"
422+
_default_port = 7687
423+
_default_target = ":"
434424

435425
def __init__(self, address):
436426
self._address = address
@@ -440,22 +430,21 @@ def address(self):
440430
return self._address
441431

442432
@classmethod
443-
def parse_target(cls, target):
433+
def _parse_target(cls, target):
444434
"""Parse a target string to produce an address."""
445435
if not target:
446-
target = cls.default_target
436+
target = cls._default_target
447437
return Address.parse(
448438
target,
449-
default_host=cls.default_host,
450-
default_port=cls.default_port,
439+
default_host=cls._default_host,
440+
default_port=cls._default_port,
451441
)
452442

453443

454444
class _Routing:
455-
# TODO: 6.0 - those attributes should be private
456-
default_host = "localhost"
457-
default_port = 7687
458-
default_targets = ": :17601 :17687"
445+
_default_host = "localhost"
446+
_default_port = 7687
447+
_default_targets = ": :17601 :17687"
459448

460449
def __init__(self, initial_addresses):
461450
self._initial_addresses = initial_addresses
@@ -465,15 +454,15 @@ def initial_addresses(self):
465454
return self._initial_addresses
466455

467456
@classmethod
468-
def parse_targets(cls, *targets):
457+
def _parse_targets(cls, *targets):
469458
"""Parse a sequence of target strings to produce an address list."""
470459
targets = " ".join(targets)
471460
if not targets:
472-
targets = cls.default_targets
461+
targets = cls._default_targets
473462
return Address.parse_list(
474463
targets,
475-
default_host=cls.default_host,
476-
default_port=cls.default_port,
464+
default_host=cls._default_host,
465+
default_port=cls._default_port,
477466
)
478467

479468

@@ -1308,10 +1297,10 @@ class AsyncBoltDriver(_Direct, AsyncDriver):
13081297
"""
13091298

13101299
@classmethod
1311-
def open(cls, target, **config):
1300+
def _open(cls, target, **config):
13121301
from .io import AsyncBoltPool
13131302

1314-
address = cls.parse_target(target)
1303+
address = cls._parse_target(target)
13151304
pool_config, default_workspace_config = Config.consume_chain(
13161305
config, AsyncPoolConfig, WorkspaceConfig
13171306
)
@@ -1342,10 +1331,10 @@ class AsyncNeo4jDriver(_Routing, AsyncDriver):
13421331
"""
13431332

13441333
@classmethod
1345-
def open(cls, *targets, routing_context=None, **config):
1334+
def _open(cls, *targets, routing_context=None, **config):
13461335
from .io import AsyncNeo4jPool
13471336

1348-
addresses = cls.parse_targets(*targets)
1337+
addresses = cls._parse_targets(*targets)
13491338
pool_config, default_workspace_config = Config.consume_chain(
13501339
config, AsyncPoolConfig, WorkspaceConfig
13511340
)

src/neo4j/_sync/driver.py

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

tests/integration/examples/test_bearer_auth_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def __init__(self, uri, token):
4444
def test_example(uri, mocker):
4545
# Currently, there is no way of running the test against a server with SSO
4646
# setup.
47-
mocker.patch("neo4j.GraphDatabase.bolt_driver")
48-
mocker.patch("neo4j.GraphDatabase.neo4j_driver")
47+
mocker.patch("neo4j.GraphDatabase._bolt_driver")
48+
mocker.patch("neo4j.GraphDatabase._neo4j_driver")
4949

5050
token = "myToken"
5151
BearerAuthExample(uri, token)
5252
calls = (
53-
neo4j.GraphDatabase.bolt_driver.call_args_list
54-
+ neo4j.GraphDatabase.neo4j_driver.call_args_list
53+
neo4j.GraphDatabase._bolt_driver.call_args_list
54+
+ neo4j.GraphDatabase._neo4j_driver.call_args_list
5555
)
5656
assert len(calls) == 1
5757
_args, kwargs = calls[0]

0 commit comments

Comments
 (0)