Skip to content

Commit d613ae5

Browse files
authored
Add __all__ to all public modules/packages (#1075)
1 parent edb7ac9 commit d613ae5

File tree

9 files changed

+123
-14
lines changed

9 files changed

+123
-14
lines changed

src/neo4j/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
_log = _getLogger("neo4j")
187187

188188

189-
def __getattr__(name):
189+
def __getattr__(name) -> _t.Any:
190190
# TODO: 6.0 - remove this
191191
if name in (
192192
"log", "Config", "PoolConfig", "SessionConfig", "WorkspaceConfig"
@@ -219,7 +219,7 @@ def __getattr__(name):
219219
raise AttributeError(f"module {__name__} has no attribute {name}")
220220

221221

222-
def __dir__():
222+
def __dir__() -> _t.List[str]:
223223
return __all__
224224

225225

src/neo4j/_meta.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def decorator(f):
116116
return t.cast(property, decorator)
117117

118118

119+
# TODO: 6.0 - remove this class, replace usage with PreviewWarning
119120
class ExperimentalWarning(Warning):
120121
""" Base class for warnings about experimental features.
121122
@@ -145,6 +146,8 @@ def foo(x):
145146
return _make_warning_decorator(message, experimental_warn)
146147

147148

149+
# TODO: 6.0 - consider moving this to the `warnings` module
150+
# and not to re-export it from the top-level package `neo4j`
148151
class PreviewWarning(Warning):
149152
"""A driver feature in preview has been used.
150153

src/neo4j/addressing.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ class _WithPeerName(te.Protocol):
3838
def getpeername(self) -> tuple: ...
3939

4040

41+
__all__ = [
42+
"Address",
43+
"IPv4Address",
44+
"IPv6Address",
45+
"ResolvedAddress",
46+
"ResolvedIPv4Address",
47+
"ResolvedIPv6Address",
48+
]
49+
50+
4151
class _AddressMeta(type(tuple)): # type: ignore[misc]
4252

4353
def __init__(cls, *args, **kwargs):
@@ -311,7 +321,7 @@ def __str__(self) -> str:
311321

312322

313323
class IPv6Address(Address):
314-
"""An IPv6 address (family ``AF_INETl``).
324+
"""An IPv6 address (family ``AF_INET6``).
315325
316326
This class should not be instantiated directly. Instead, use
317327
:class:`.Address` or one of its factory methods.
@@ -323,6 +333,7 @@ def __str__(self) -> str:
323333
return "[{}]:{}".format(*self)
324334

325335

336+
# TODO: 6.0 - make this class private
326337
class ResolvedAddress(Address):
327338

328339
_unresolved_host_name: str
@@ -342,9 +353,11 @@ def __new__(cls, iterable, *, host_name: str) -> ResolvedAddress:
342353
return new
343354

344355

356+
# TODO: 6.0 - make this class private
345357
class ResolvedIPv4Address(IPv4Address, ResolvedAddress):
346358
pass
347359

348360

361+
# TODO: 6.0 - make this class private
349362
class ResolvedIPv6Address(IPv6Address, ResolvedAddress):
350363
pass

src/neo4j/api.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,51 @@
4040
_Protocol = object
4141

4242

43+
__all__ = [
44+
"READ_ACCESS",
45+
"WRITE_ACCESS",
46+
"DRIVER_BOLT",
47+
"DRIVER_NEO4J",
48+
"SECURITY_TYPE_NOT_SECURE",
49+
"SECURITY_TYPE_SELF_SIGNED_CERTIFICATE",
50+
"SECURITY_TYPE_SECURE",
51+
"URI_SCHEME_BOLT",
52+
"URI_SCHEME_BOLT_SELF_SIGNED_CERTIFICATE",
53+
"URI_SCHEME_BOLT_SECURE",
54+
"URI_SCHEME_NEO4J",
55+
"URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE",
56+
"URI_SCHEME_NEO4J_SECURE",
57+
"URI_SCHEME_BOLT_ROUTING",
58+
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
59+
"TRUST_ALL_CERTIFICATES",
60+
"SYSTEM_DATABASE",
61+
"DEFAULT_DATABASE",
62+
"Auth",
63+
"AuthToken",
64+
"basic_auth",
65+
"kerberos_auth",
66+
"bearer_auth",
67+
"custom_auth",
68+
"Bookmark",
69+
"Bookmarks",
70+
"ServerInfo",
71+
"Version",
72+
"BookmarkManager",
73+
"AsyncBookmarkManager",
74+
"parse_neo4j_uri",
75+
"check_access_mode",
76+
"parse_routing_context",
77+
]
78+
79+
4380
READ_ACCESS: te.Final[str] = "READ"
4481
WRITE_ACCESS: te.Final[str] = "WRITE"
4582

83+
# TODO: 6.0 - make these 2 constants private
4684
DRIVER_BOLT: te.Final[str] = "DRIVER_BOLT"
4785
DRIVER_NEO4J: te.Final[str] = "DRIVER_NEO4J"
4886

87+
# TODO: 6.0 - make these 3 constants private
4988
SECURITY_TYPE_NOT_SECURE: te.Final[str] = "SECURITY_TYPE_NOT_SECURE"
5089
SECURITY_TYPE_SELF_SIGNED_CERTIFICATE: te.Final[str] = \
5190
"SECURITY_TYPE_SELF_SIGNED_CERTIFICATE"
@@ -354,6 +393,9 @@ def update(self, metadata: dict) -> None:
354393
self._metadata.update(metadata)
355394

356395

396+
# TODO: 6.0 - this class should not be public.
397+
# As far the user is concerned, protocol versions should simply be a
398+
# tuple[int, int].
357399
class Version(tuple):
358400

359401
def __new__(cls, *v):
@@ -480,6 +522,7 @@ async def get_bookmarks(self) -> t.Collection[str]:
480522
get_bookmarks.__doc__ = BookmarkManager.get_bookmarks.__doc__
481523

482524

525+
# TODO: 6.0 - make this function private
483526
def parse_neo4j_uri(uri):
484527
parsed = urlparse(uri)
485528

@@ -525,6 +568,7 @@ def parse_neo4j_uri(uri):
525568
return driver_type, security_type, parsed
526569

527570

571+
# TODO: 6.0 - make this function private
528572
def check_access_mode(access_mode):
529573
if access_mode is None:
530574
return WRITE_ACCESS
@@ -535,6 +579,7 @@ def check_access_mode(access_mode):
535579
return access_mode
536580

537581

582+
# TODO: 6.0 - make this function private
538583
def parse_routing_context(query):
539584
""" Parse the query portion of a URI to generate a routing context dictionary.
540585
"""

src/neo4j/exceptions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,48 @@
101101
_TSession = t.Union["AsyncSession", "Session"]
102102

103103

104+
__all__ = [
105+
# TODO: 6.0 - make these constants private
106+
"CLASSIFICATION_CLIENT",
107+
"CLASSIFICATION_TRANSIENT",
108+
"CLASSIFICATION_DATABASE",
109+
"ERROR_REWRITE_MAP",
110+
111+
"Neo4jError",
112+
"ClientError",
113+
"CypherSyntaxError",
114+
"CypherTypeError",
115+
"ConstraintError",
116+
"AuthError",
117+
"TokenExpired",
118+
"Forbidden",
119+
"DatabaseError",
120+
"TransientError",
121+
"DatabaseUnavailable",
122+
"NotALeader",
123+
"ForbiddenOnReadOnlyDatabase",
124+
"DriverError",
125+
"SessionError",
126+
"TransactionError",
127+
"TransactionNestingError",
128+
"ResultError",
129+
"ResultFailedError",
130+
"ResultConsumedError",
131+
"ResultNotSingleError",
132+
"BrokenRecordError",
133+
"SessionExpired",
134+
"ServiceUnavailable",
135+
"RoutingServiceUnavailable",
136+
"WriteServiceUnavailable",
137+
"ReadServiceUnavailable",
138+
"IncompleteCommit",
139+
"ConfigurationError",
140+
"AuthConfigurationError",
141+
"CertificateConfigurationError",
142+
"UnsupportedServerProduct",
143+
]
144+
145+
104146
CLASSIFICATION_CLIENT: te.Final[str] = "ClientError"
105147
CLASSIFICATION_TRANSIENT: te.Final[str] = "TransientError"
106148
CLASSIFICATION_DATABASE: te.Final[str] = "DatabaseError"

src/neo4j/meta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
deprecation_warn(
4141
"The module `neo4j.meta` was made internal and will "
4242
"no longer be available for import in future versions."
43-
"`ExperimentalWarning` can be imported from `neo4j` directly and "
44-
"`neo4j.meta.version` is exposed as `neo4j.__version__`.",
43+
"`ExperimentalWarning` can be imported from `neo4j.warnings` and "
44+
"`neo4j.meta.version` is exposed through `neo4j.__version__`.",
4545
stack_level=2
4646
)

src/neo4j/warnings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
from ._work.summary import SummaryNotification
2323

2424

25+
__all__ = [
26+
"Neo4jWarning",
27+
"Neo4jDeprecationWarning",
28+
]
29+
30+
2531
class Neo4jWarning(Warning):
2632
"""
2733
Warning emitted for notifications sent by the server.
2834
2935
Which notifications trigger a warning can be controlled by a
30-
configuration: :ref:`driver-warn-notification-severity-ref`
36+
configuration option: :ref:`driver-warn-notification-severity-ref`
3137
3238
**This is experimental** (see :ref:`filter-warnings-ref`).
3339
It might be changed or removed any time even without prior notice.

tests/unit/async_/test_driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ def forget(self, databases: t.Iterable[str]) -> None:
453453

454454
@mark_async_test
455455
async def test_with_static_client_certificate() -> None:
456-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
456+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
457457
cert = ClientCertificate("foo")
458-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
458+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
459459
async with AsyncGraphDatabase.driver(
460460
"bolt://localhost", client_certificate=cert
461461
) as driver:
@@ -474,7 +474,7 @@ async def get_certificate(self) -> t.Optional[ClientCertificate]:
474474
return None
475475

476476
provider = Provider()
477-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
477+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
478478
async with AsyncGraphDatabase.driver(
479479
"bolt://localhost", client_certificate=provider
480480
) as driver:
@@ -490,7 +490,7 @@ async def get_certificate(self) -> t.Optional[ClientCertificate]:
490490
return None
491491

492492
provider = Provider()
493-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
493+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
494494
async with AsyncGraphDatabase.driver(
495495
"bolt://localhost", client_certificate=provider
496496
) as driver:

tests/unit/sync/test_driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ def forget(self, databases: t.Iterable[str]) -> None:
452452

453453
@mark_sync_test
454454
def test_with_static_client_certificate() -> None:
455-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
455+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
456456
cert = ClientCertificate("foo")
457-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
457+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
458458
with GraphDatabase.driver(
459459
"bolt://localhost", client_certificate=cert
460460
) as driver:
@@ -473,7 +473,7 @@ def get_certificate(self) -> t.Optional[ClientCertificate]:
473473
return None
474474

475475
provider = Provider()
476-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
476+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
477477
with GraphDatabase.driver(
478478
"bolt://localhost", client_certificate=provider
479479
) as driver:
@@ -489,7 +489,7 @@ def get_certificate(self) -> t.Optional[ClientCertificate]:
489489
return None
490490

491491
provider = Provider()
492-
with pytest.warns(neo4j.PreviewWarning, match="Mutual TLS"):
492+
with pytest.warns(PreviewWarning, match="Mutual TLS"):
493493
with GraphDatabase.driver(
494494
"bolt://localhost", client_certificate=provider
495495
) as driver:

0 commit comments

Comments
 (0)