Skip to content

Commit 1a94d76

Browse files
robsdedudebigmontz
andauthored
Clean up API docs (#735)
* remove year from copy-right * amend imports where missing * improve code readability * document `srid` values of spatial types * document `ResultConsumedError` can be raised from `Result.fetch` Co-authored-by: Antonio Barcélos <antonio.barcelos@neo4j.com>
1 parent d3a1f46 commit 1a94d76

File tree

11 files changed

+105
-63
lines changed

11 files changed

+105
-63
lines changed

docs/source/api.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ For example:
275275
raise gaierror("Unexpected socket address %r" % socket_address)
276276
277277
driver = GraphDatabase.driver("neo4j://example.com:9999",
278-
auth=("neo4j", "password"),
279-
resolver=custom_resolver)
278+
auth=("neo4j", "password"),
279+
resolver=custom_resolver)
280280
281281
282282
:Default: :const:`None`
@@ -541,9 +541,9 @@ Name of the database to query.
541541

542542

543543
.. py:attribute:: neo4j.DEFAULT_DATABASE
544-
:noindex:
544+
:noindex:
545545

546-
This will use the default database on the Neo4j instance.
546+
This will use the default database on the Neo4j instance.
547547

548548

549549
.. Note::
@@ -558,9 +558,10 @@ Name of the database to query.
558558

559559
.. code-block:: python
560560
561-
from neo4j import GraphDatabase
562-
driver = GraphDatabase.driver(uri, auth=(user, password))
563-
session = driver.session(database="system")
561+
from neo4j import GraphDatabase
562+
563+
driver = GraphDatabase.driver(uri, auth=(user, password))
564+
session = driver.session(database="system")
564565
565566
566567
:Default: ``neo4j.DEFAULT_DATABASE``
@@ -593,9 +594,10 @@ context of the impersonated user. For this, the user for which the
593594

594595
.. code-block:: python
595596
596-
from neo4j import GraphDatabase
597-
driver = GraphDatabase.driver(uri, auth=(user, password))
598-
session = driver.session(impersonated_user="alice")
597+
from neo4j import GraphDatabase
598+
599+
driver = GraphDatabase.driver(uri, auth=(user, password))
600+
session = driver.session(impersonated_user="alice")
599601
600602
601603
:Default: :const:`None`
@@ -740,8 +742,8 @@ Example:
740742
def set_person_name(tx, node_id, name):
741743
query = "MATCH (a:Person) WHERE id(a) = $id SET a.name = $name"
742744
result = tx.run(query, id=node_id, name=name)
743-
info = result.consume()
744-
# use the info for logging etc.
745+
summary = result.consume()
746+
# use the summary for logging etc.
745747
746748
.. _managed-transactions-ref:
747749

docs/source/async_api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ Example:
446446
async def set_person_name(tx, node_id, name):
447447
query = "MATCH (a:Person) WHERE id(a) = $id SET a.name = $name"
448448
result = await tx.run(query, id=node_id, name=name)
449-
info = await result.consume()
450-
# use the info for logging etc.
449+
summary = await result.consume()
450+
# use the summary for logging etc.
451451
452452
.. _async-managed-transactions-ref:
453453

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
# General information about the project.
5959
project = 'Neo4j Python Driver'
60-
copyright = '2002-2020 Neo4j, Inc.'
60+
copyright = 'Neo4j, Inc.'
6161
author = 'Neo4j, Inc.'
6262

6363
# The version info for the project you're documenting, acts as replacement for

docs/source/types/spatial.rst

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Point
1212

1313
.. autoclass:: neo4j.spatial.Point
1414
:show-inheritance:
15-
:members: srid
15+
:members:
1616

1717

1818
CartesianPoint
@@ -21,9 +21,6 @@ CartesianPoint
2121
.. autoclass:: neo4j.spatial.CartesianPoint
2222
:show-inheritance:
2323

24-
.. property:: srid
25-
:type: int
26-
2724
.. property:: x
2825
:type: float
2926

@@ -39,24 +36,28 @@ CartesianPoint
3936

4037
Same value as ``point[2]``.
4138

42-
Only available if the point is in space.
39+
Only available if the point is in 3D space.
4340

4441

4542
Examples
4643
--------
4744

4845
.. code-block:: python
4946
50-
point=CartesianPoint((1.23, 4.56)
47+
from neo4j.spatial import CartesianPoint
5148
52-
print(point.x, point.y)
49+
point = CartesianPoint((1.23, 4.56)
50+
print(point.x, point.y, point.srid)
51+
# 1.23 4.56 7203
5352
5453
5554
.. code-block:: python
5655
57-
point=CartesianPoint((1.23, 4.56, 7.89)
56+
from neo4j.spatial import CartesianPoint
5857
59-
print(point.x, point.y, point.z)
58+
point = CartesianPoint((1.23, 4.56, 7.89)
59+
print(point.x, point.y, point.z, point.srid)
60+
# 1.23 4.56 7.8 9157
6061
6162
6263
WGS84Point
@@ -65,9 +66,6 @@ WGS84Point
6566
.. autoclass:: neo4j.spatial.WGS84Point
6667
:show-inheritance:
6768
68-
.. property:: srid
69-
:type: int
70-
7169
.. property:: x
7270
:type: float
7371
@@ -83,7 +81,7 @@ WGS84Point
8381
8482
Same value as ``point[2]``.
8583
86-
Only available if the point is in space.
84+
Only available if the point is in 3D space.
8785
8886
.. property:: longitude
8987
:type: float
@@ -100,19 +98,25 @@ WGS84Point
10098
10199
Alias for :attr:`.z`.
102100
103-
Only available if the point is in space.
101+
Only available if the point is in 3D space.
104102
105103
106104
Examples
107105
--------
108106
109107
.. code-block:: python
110108
111-
point=WGS84Point((1.23, 4.56))
112-
print(point.longitude, point.latitude)
109+
from neo4j.spatial import WGS84Point
110+
111+
point = WGS84Point((1.23, 4.56))
112+
print(point.longitude, point.latitude, point.srid)
113+
# 1.23 4.56 4326
113114
114115
115116
.. code-block:: python
116117
117-
point=WGS84Point((1.23, 4.56, 7.89))
118-
print(point.longitude, point.latitude, point.height)
118+
from neo4j.spatial import WGS84Point
119+
120+
point = WGS84Point((1.23, 4.56, 7.89))
121+
print(point.longitude, point.latitude, point.height, point.srid)
122+
# 1.23 4.56 7.89 4979

neo4j/_async/work/result.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def on_success(summary_metadata):
207207
async def __aiter__(self):
208208
"""Iterator returning Records.
209209
:returns: Record, it is an immutable ordered collection of key-value pairs.
210-
:rtype: :class:`neo4j.AsyncRecord`
210+
:rtype: :class:`neo4j.Record`
211211
"""
212212
while self._record_buffer or self._attached:
213213
if self._record_buffer:
@@ -316,17 +316,19 @@ async def consume(self):
316316
317317
Example::
318318
319-
def create_node_tx(tx, name):
319+
async def create_node_tx(tx, name):
320320
result = await tx.run(
321321
"CREATE (n:ExampleNode { name: $name }) RETURN n", name=name
322322
)
323323
record = await result.single()
324324
value = record.value()
325-
info = await result.consume()
326-
return value, info
325+
summary = await result.consume()
326+
return value, summary
327327
328328
async with driver.session() as session:
329-
node_id, info = await session.write_transaction(create_node_tx, "example")
329+
node_id, summary = await session.write_transaction(
330+
create_node_tx, "example"
331+
)
330332
331333
Example::
332334
@@ -337,13 +339,16 @@ async def get_two_tx(tx):
337339
if len(values) >= 2:
338340
break
339341
values.append(record.values())
342+
# or shorter: values = [record.values()
343+
# for record in await result.fetch(2)]
344+
340345
# discard the remaining records if there are any
341-
info = await result.consume()
342-
# use the info for logging etc.
343-
return values, info
346+
summary = await result.consume()
347+
# use the summary for logging etc.
348+
return values, summary
344349
345-
with driver.session() as session:
346-
values, info = session.read_transaction(get_two_tx)
350+
async with driver.session() as session:
351+
values, summary = await session.read_transaction(get_two_tx)
347352
348353
:returns: The :class:`neo4j.ResultSummary` for this result
349354
@@ -424,7 +429,11 @@ async def fetch(self, n):
424429
:param n: the maximum number of records to fetch.
425430
:type n: int
426431
427-
:returns: list of :class:`neo4j.AsyncRecord`
432+
:returns: list of :class:`neo4j.Record`
433+
434+
:raises ResultConsumedError: if the transaction from which this result
435+
was obtained has been closed or the Result has been explicitly
436+
consumed.
428437
429438
.. versionadded:: 5.0
430439
"""
@@ -438,7 +447,8 @@ async def peek(self):
438447
"""Obtain the next record from this result without consuming it.
439448
This leaves the record in the buffer for further processing.
440449
441-
:returns: the next :class:`.Record` or :const:`None` if none remain
450+
:returns: the next :class:`neo4j.Record` or :const:`None` if none
451+
remain.
442452
443453
:raises ResultConsumedError: if the transaction from which this result
444454
was obtained has been closed or the Result has been explicitly
@@ -474,7 +484,7 @@ async def graph(self):
474484
async def value(self, key=0, default=None):
475485
"""Helper function that return the remainder of the result as a list of values.
476486
477-
See :class:`neo4j.AsyncRecord.value`
487+
See :class:`neo4j.Record.value`
478488
479489
:param key: field to return for each remaining record. Obtain a single value from the record by index or key.
480490
:param default: default value, used if the index of key is unavailable
@@ -494,7 +504,7 @@ async def value(self, key=0, default=None):
494504
async def values(self, *keys):
495505
"""Helper function that return the remainder of the result as a list of values lists.
496506
497-
See :class:`neo4j.AsyncRecord.values`
507+
See :class:`neo4j.Record.values`
498508
499509
:param keys: fields to return for each remaining record. Optionally filtering to include only certain values by index or key.
500510
@@ -513,7 +523,7 @@ async def values(self, *keys):
513523
async def data(self, *keys):
514524
"""Helper function that return the remainder of the result as a list of dictionaries.
515525
516-
See :class:`neo4j.AsyncRecord.data`
526+
See :class:`neo4j.Record.data`
517527
518528
:param keys: fields to return for each remaining record. Optionally filtering to include only certain values by index or key.
519529

neo4j/_async/work/session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,12 @@ async def get_two_tx(tx):
468468
if len(values) >= 2:
469469
break
470470
values.append(record.values())
471+
# or shorter: values = [record.values()
472+
# for record in await result.fetch(2)]
473+
471474
# discard the remaining records if there are any
472-
info = await result.consume()
473-
# use the info for logging etc.
475+
summary = await result.consume()
476+
# use the summary for logging etc.
474477
return values
475478
476479
async with driver.session() as session:

neo4j/_conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class TrustSystemCAs(TrustStore):
3030
3131
For example::
3232
33+
import neo4j
34+
3335
driver = neo4j.GraphDatabase.driver(
3436
url, auth=auth, trusted_certificates=neo4j.TrustSystemCAs()
3537
)
@@ -48,6 +50,8 @@ class TrustAll(TrustStore):
4850
4951
For example::
5052
53+
import neo4j
54+
5155
driver = neo4j.GraphDatabase.driver(
5256
url, auth=auth, trusted_certificates=neo4j.TrustAll()
5357
)
@@ -69,6 +73,8 @@ class TrustCustomCAs(TrustStore):
6973
7074
For example::
7175
76+
import neo4j
77+
7278
driver = neo4j.GraphDatabase.driver(
7379
url, auth=auth,
7480
trusted_certificates=neo4j.TrustCustomCAs(

neo4j/_sync/work/result.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,13 @@ def create_node_tx(tx, name):
322322
)
323323
record = result.single()
324324
value = record.value()
325-
info = result.consume()
326-
return value, info
325+
summary = result.consume()
326+
return value, summary
327327
328328
with driver.session() as session:
329-
node_id, info = session.write_transaction(create_node_tx, "example")
329+
node_id, summary = session.write_transaction(
330+
create_node_tx, "example"
331+
)
330332
331333
Example::
332334
@@ -337,13 +339,16 @@ def get_two_tx(tx):
337339
if len(values) >= 2:
338340
break
339341
values.append(record.values())
342+
# or shorter: values = [record.values()
343+
# for record in result.fetch(2)]
344+
340345
# discard the remaining records if there are any
341-
info = result.consume()
342-
# use the info for logging etc.
343-
return values, info
346+
summary = result.consume()
347+
# use the summary for logging etc.
348+
return values, summary
344349
345350
with driver.session() as session:
346-
values, info = session.read_transaction(get_two_tx)
351+
values, summary = session.read_transaction(get_two_tx)
347352
348353
:returns: The :class:`neo4j.ResultSummary` for this result
349354
@@ -426,6 +431,10 @@ def fetch(self, n):
426431
427432
:returns: list of :class:`neo4j.Record`
428433
434+
:raises ResultConsumedError: if the transaction from which this result
435+
was obtained has been closed or the Result has been explicitly
436+
consumed.
437+
429438
.. versionadded:: 5.0
430439
"""
431440
self._buffer(n)
@@ -438,7 +447,8 @@ def peek(self):
438447
"""Obtain the next record from this result without consuming it.
439448
This leaves the record in the buffer for further processing.
440449
441-
:returns: the next :class:`.Record` or :const:`None` if none remain
450+
:returns: the next :class:`neo4j.Record` or :const:`None` if none
451+
remain.
442452
443453
:raises ResultConsumedError: if the transaction from which this result
444454
was obtained has been closed or the Result has been explicitly

0 commit comments

Comments
 (0)