Skip to content

Type Hints #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ trim_trailing_whitespace = true
[*.bat]
end_of_line = crlf

[*.py]
max_line_length = 79
[*{.py,pyi}]
indent_style = space
indent_size = 4

[*.py]
max_line_length = 79

[*.pyi]
max_line_length = 130
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ repos:
entry: bin/make-unasync
language: system
files: "^(neo4j/_async|tests/(unit|integration)/async_|testkitbackend/_async)/.*"
- id: mypy
name: mypy static type check
entry: mypy
args: [ --show-error-codes, neo4j, tests, testkitbackend ]
'types_or': [ python, pyi ]
language: system
pass_filenames: false
require_serial: true
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
be used by client code. `Record` should be imported directly from `neo4j`
instead. `neo4j.data.DataHydrator` and `neo4j.data.DataDeydrator` have been
removed without replacement.
- Removed undocumented config options that had no effect:
`protocol_version` and `init_size`.
- Introduced `neo4j.exceptions.SessionError` that is raised when trying to
execute work on a closed or otherwise terminated session.

Expand Down
3 changes: 3 additions & 0 deletions bin/make-unasync
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class CustomRule(unasync.Rule):
def __init__(self, *args, **kwargs):
super(CustomRule, self).__init__(*args, **kwargs)
self.out_files = []
# it's not pretty, but it works
# typing.Awaitable[...] -> typing.Union[...]
self.token_replacements["Awaitable"] = "Union"

def _unasync_tokens(self, tokens):
# copy from unasync to hook into string handling
Expand Down
65 changes: 35 additions & 30 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1267,43 +1267,44 @@ Server-side errors
* :class:`neo4j.exceptions.ForbiddenOnReadOnlyDatabase`


.. autoclass:: neo4j.exceptions.Neo4jError
.. autoexception:: neo4j.exceptions.Neo4jError()
:show-inheritance:
:members: message, code, is_retriable, is_retryable

.. autoclass:: neo4j.exceptions.ClientError
.. autoexception:: neo4j.exceptions.ClientError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.CypherSyntaxError
.. autoexception:: neo4j.exceptions.CypherSyntaxError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.CypherTypeError
.. autoexception:: neo4j.exceptions.CypherTypeError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ConstraintError
.. autoexception:: neo4j.exceptions.ConstraintError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.AuthError
.. autoexception:: neo4j.exceptions.AuthError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.TokenExpired
.. autoexception:: neo4j.exceptions.TokenExpired()
:show-inheritance:

.. autoclass:: neo4j.exceptions.Forbidden
.. autoexception:: neo4j.exceptions.Forbidden()
:show-inheritance:

.. autoclass:: neo4j.exceptions.DatabaseError
.. autoexception:: neo4j.exceptions.DatabaseError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.TransientError
.. autoexception:: neo4j.exceptions.TransientError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.DatabaseUnavailable
.. autoexception:: neo4j.exceptions.DatabaseUnavailable()
:show-inheritance:

.. autoclass:: neo4j.exceptions.NotALeader
.. autoexception:: neo4j.exceptions.NotALeader()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ForbiddenOnReadOnlyDatabase
.. autoexception:: neo4j.exceptions.ForbiddenOnReadOnlyDatabase()
:show-inheritance:


Expand Down Expand Up @@ -1350,55 +1351,59 @@ Client-side errors
* :class:`neo4j.exceptions.CertificateConfigurationError`


.. autoclass:: neo4j.exceptions.DriverError
.. autoexception:: neo4j.exceptions.DriverError()
:show-inheritance:
:members: is_retryable

.. autoclass:: neo4j.exceptions.SessionError
.. autoexception:: neo4j.exceptions.SessionError()
:show-inheritance:
:members: session

.. autoclass:: neo4j.exceptions.TransactionError
.. autoexception:: neo4j.exceptions.TransactionError()
:show-inheritance:
:members: transaction

.. autoclass:: neo4j.exceptions.TransactionNestingError
.. autoexception:: neo4j.exceptions.TransactionNestingError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ResultError
.. autoexception:: neo4j.exceptions.ResultError()
:show-inheritance:
:members: result

.. autoclass:: neo4j.exceptions.ResultConsumedError
.. autoexception:: neo4j.exceptions.ResultConsumedError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ResultNotSingleError
.. autoexception:: neo4j.exceptions.ResultNotSingleError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.BrokenRecordError
.. autoexception:: neo4j.exceptions.BrokenRecordError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.SessionExpired
.. autoexception:: neo4j.exceptions.SessionExpired()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ServiceUnavailable
.. autoexception:: neo4j.exceptions.ServiceUnavailable()
:show-inheritance:

.. autoclass:: neo4j.exceptions.RoutingServiceUnavailable
.. autoexception:: neo4j.exceptions.RoutingServiceUnavailable()
:show-inheritance:

.. autoclass:: neo4j.exceptions.WriteServiceUnavailable
.. autoexception:: neo4j.exceptions.WriteServiceUnavailable()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ReadServiceUnavailable
.. autoexception:: neo4j.exceptions.ReadServiceUnavailable()
:show-inheritance:

.. autoclass:: neo4j.exceptions.IncompleteCommit
.. autoexception:: neo4j.exceptions.IncompleteCommit()
:show-inheritance:

.. autoclass:: neo4j.exceptions.ConfigurationError
.. autoexception:: neo4j.exceptions.ConfigurationError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.AuthConfigurationError
.. autoexception:: neo4j.exceptions.AuthConfigurationError()
:show-inheritance:

.. autoclass:: neo4j.exceptions.CertificateConfigurationError
.. autoexception:: neo4j.exceptions.CertificateConfigurationError()
:show-inheritance:


Expand Down
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

# Don't include type hints in function signatures
autodoc_typehints = "description"


# -- Options for HTML output ----------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions neo4j/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"BoltDriver",
"Bookmark",
"Bookmarks",
"Config",
"custom_auth",
"DEFAULT_DATABASE",
"Driver",
Expand All @@ -117,15 +118,18 @@
"IPv4Address",
"IPv6Address",
"kerberos_auth",
"log",
"ManagedTransaction",
"Neo4jDriver",
"PoolConfig",
"Query",
"READ_ACCESS",
"Record",
"Result",
"ResultSummary",
"ServerInfo",
"Session",
"SessionConfig",
"SummaryCounters",
"Transaction",
"TRUST_ALL_CERTIFICATES",
Expand All @@ -135,6 +139,7 @@
"TrustSystemCAs",
"unit_of_work",
"Version",
"WorkspaceConfig",
"WRITE_ACCESS",
]

Expand Down
Loading