Skip to content

Commit 799720d

Browse files
robsdedudebigmontz
andauthored
Type Hints (#767)
Add type annotations to public facing APIs Signed-off-by: Rouven Bauer <[email protected]> Co-authored-by: Antonio Barcelos <[email protected]>
1 parent ec67996 commit 799720d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2757
-1965
lines changed

.editorconfig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ trim_trailing_whitespace = true
1616
[*.bat]
1717
end_of_line = crlf
1818

19-
[*.py]
20-
max_line_length = 79
19+
[*{.py,pyi}]
2120
indent_style = space
2221
indent_size = 4
22+
23+
[*.py]
24+
max_line_length = 79
25+
26+
[*.pyi]
27+
max_line_length = 130

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ repos:
3434
entry: bin/make-unasync
3535
language: system
3636
files: "^(neo4j/_async|tests/(unit|integration)/async_|testkitbackend/_async)/.*"
37+
- id: mypy
38+
name: mypy static type check
39+
entry: mypy
40+
args: [ --show-error-codes, neo4j, tests, testkitbackend ]
41+
'types_or': [ python, pyi ]
42+
language: system
43+
pass_filenames: false
44+
require_serial: true

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
be used by client code. `Record` should be imported directly from `neo4j`
120120
instead. `neo4j.data.DataHydrator` and `neo4j.data.DataDeydrator` have been
121121
removed without replacement.
122+
- Removed undocumented config options that had no effect:
123+
`protocol_version` and `init_size`.
122124
- Introduced `neo4j.exceptions.SessionError` that is raised when trying to
123125
execute work on a closed or otherwise terminated session.
124126

bin/make-unasync

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class CustomRule(unasync.Rule):
104104
def __init__(self, *args, **kwargs):
105105
super(CustomRule, self).__init__(*args, **kwargs)
106106
self.out_files = []
107+
# it's not pretty, but it works
108+
# typing.Awaitable[...] -> typing.Union[...]
109+
self.token_replacements["Awaitable"] = "Union"
107110

108111
def _unasync_tokens(self, tokens):
109112
# copy from unasync to hook into string handling

docs/source/api.rst

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,43 +1267,44 @@ Server-side errors
12671267
* :class:`neo4j.exceptions.ForbiddenOnReadOnlyDatabase`
12681268

12691269

1270-
.. autoclass:: neo4j.exceptions.Neo4jError
1270+
.. autoexception:: neo4j.exceptions.Neo4jError()
1271+
:show-inheritance:
12711272
:members: message, code, is_retriable, is_retryable
12721273

1273-
.. autoclass:: neo4j.exceptions.ClientError
1274+
.. autoexception:: neo4j.exceptions.ClientError()
12741275
:show-inheritance:
12751276

1276-
.. autoclass:: neo4j.exceptions.CypherSyntaxError
1277+
.. autoexception:: neo4j.exceptions.CypherSyntaxError()
12771278
:show-inheritance:
12781279

1279-
.. autoclass:: neo4j.exceptions.CypherTypeError
1280+
.. autoexception:: neo4j.exceptions.CypherTypeError()
12801281
:show-inheritance:
12811282

1282-
.. autoclass:: neo4j.exceptions.ConstraintError
1283+
.. autoexception:: neo4j.exceptions.ConstraintError()
12831284
:show-inheritance:
12841285

1285-
.. autoclass:: neo4j.exceptions.AuthError
1286+
.. autoexception:: neo4j.exceptions.AuthError()
12861287
:show-inheritance:
12871288

1288-
.. autoclass:: neo4j.exceptions.TokenExpired
1289+
.. autoexception:: neo4j.exceptions.TokenExpired()
12891290
:show-inheritance:
12901291

1291-
.. autoclass:: neo4j.exceptions.Forbidden
1292+
.. autoexception:: neo4j.exceptions.Forbidden()
12921293
:show-inheritance:
12931294

1294-
.. autoclass:: neo4j.exceptions.DatabaseError
1295+
.. autoexception:: neo4j.exceptions.DatabaseError()
12951296
:show-inheritance:
12961297

1297-
.. autoclass:: neo4j.exceptions.TransientError
1298+
.. autoexception:: neo4j.exceptions.TransientError()
12981299
:show-inheritance:
12991300

1300-
.. autoclass:: neo4j.exceptions.DatabaseUnavailable
1301+
.. autoexception:: neo4j.exceptions.DatabaseUnavailable()
13011302
:show-inheritance:
13021303

1303-
.. autoclass:: neo4j.exceptions.NotALeader
1304+
.. autoexception:: neo4j.exceptions.NotALeader()
13041305
:show-inheritance:
13051306

1306-
.. autoclass:: neo4j.exceptions.ForbiddenOnReadOnlyDatabase
1307+
.. autoexception:: neo4j.exceptions.ForbiddenOnReadOnlyDatabase()
13071308
:show-inheritance:
13081309

13091310

@@ -1350,55 +1351,59 @@ Client-side errors
13501351
* :class:`neo4j.exceptions.CertificateConfigurationError`
13511352

13521353

1353-
.. autoclass:: neo4j.exceptions.DriverError
1354+
.. autoexception:: neo4j.exceptions.DriverError()
1355+
:show-inheritance:
13541356
:members: is_retryable
13551357

1356-
.. autoclass:: neo4j.exceptions.SessionError
1358+
.. autoexception:: neo4j.exceptions.SessionError()
13571359
:show-inheritance:
1360+
:members: session
13581361

1359-
.. autoclass:: neo4j.exceptions.TransactionError
1362+
.. autoexception:: neo4j.exceptions.TransactionError()
13601363
:show-inheritance:
1364+
:members: transaction
13611365

1362-
.. autoclass:: neo4j.exceptions.TransactionNestingError
1366+
.. autoexception:: neo4j.exceptions.TransactionNestingError()
13631367
:show-inheritance:
13641368

1365-
.. autoclass:: neo4j.exceptions.ResultError
1369+
.. autoexception:: neo4j.exceptions.ResultError()
13661370
:show-inheritance:
1371+
:members: result
13671372

1368-
.. autoclass:: neo4j.exceptions.ResultConsumedError
1373+
.. autoexception:: neo4j.exceptions.ResultConsumedError()
13691374
:show-inheritance:
13701375

1371-
.. autoclass:: neo4j.exceptions.ResultNotSingleError
1376+
.. autoexception:: neo4j.exceptions.ResultNotSingleError()
13721377
:show-inheritance:
13731378

1374-
.. autoclass:: neo4j.exceptions.BrokenRecordError
1379+
.. autoexception:: neo4j.exceptions.BrokenRecordError()
13751380
:show-inheritance:
13761381

1377-
.. autoclass:: neo4j.exceptions.SessionExpired
1382+
.. autoexception:: neo4j.exceptions.SessionExpired()
13781383
:show-inheritance:
13791384

1380-
.. autoclass:: neo4j.exceptions.ServiceUnavailable
1385+
.. autoexception:: neo4j.exceptions.ServiceUnavailable()
13811386
:show-inheritance:
13821387

1383-
.. autoclass:: neo4j.exceptions.RoutingServiceUnavailable
1388+
.. autoexception:: neo4j.exceptions.RoutingServiceUnavailable()
13841389
:show-inheritance:
13851390

1386-
.. autoclass:: neo4j.exceptions.WriteServiceUnavailable
1391+
.. autoexception:: neo4j.exceptions.WriteServiceUnavailable()
13871392
:show-inheritance:
13881393

1389-
.. autoclass:: neo4j.exceptions.ReadServiceUnavailable
1394+
.. autoexception:: neo4j.exceptions.ReadServiceUnavailable()
13901395
:show-inheritance:
13911396

1392-
.. autoclass:: neo4j.exceptions.IncompleteCommit
1397+
.. autoexception:: neo4j.exceptions.IncompleteCommit()
13931398
:show-inheritance:
13941399

1395-
.. autoclass:: neo4j.exceptions.ConfigurationError
1400+
.. autoexception:: neo4j.exceptions.ConfigurationError()
13961401
:show-inheritance:
13971402

1398-
.. autoclass:: neo4j.exceptions.AuthConfigurationError
1403+
.. autoexception:: neo4j.exceptions.AuthConfigurationError()
13991404
:show-inheritance:
14001405

1401-
.. autoclass:: neo4j.exceptions.CertificateConfigurationError
1406+
.. autoexception:: neo4j.exceptions.CertificateConfigurationError()
14021407
:show-inheritance:
14031408

14041409

docs/source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
# If true, `todo` and `todoList` produce output, else they produce nothing.
116116
todo_include_todos = True
117117

118+
# Don't include type hints in function signatures
119+
autodoc_typehints = "description"
120+
118121

119122
# -- Options for HTML output ----------------------------------------------
120123

neo4j/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"BoltDriver",
109109
"Bookmark",
110110
"Bookmarks",
111+
"Config",
111112
"custom_auth",
112113
"DEFAULT_DATABASE",
113114
"Driver",
@@ -117,15 +118,18 @@
117118
"IPv4Address",
118119
"IPv6Address",
119120
"kerberos_auth",
121+
"log",
120122
"ManagedTransaction",
121123
"Neo4jDriver",
124+
"PoolConfig",
122125
"Query",
123126
"READ_ACCESS",
124127
"Record",
125128
"Result",
126129
"ResultSummary",
127130
"ServerInfo",
128131
"Session",
132+
"SessionConfig",
129133
"SummaryCounters",
130134
"Transaction",
131135
"TRUST_ALL_CERTIFICATES",
@@ -135,6 +139,7 @@
135139
"TrustSystemCAs",
136140
"unit_of_work",
137141
"Version",
142+
"WorkspaceConfig",
138143
"WRITE_ACCESS",
139144
]
140145

0 commit comments

Comments
 (0)