Skip to content

Commit

Permalink
Merge pull request #843 from neo4j-contrib/housekeeping/mypy
Browse files Browse the repository at this point in the history
mypy
  • Loading branch information
mariusconjeaud authored Dec 13, 2024
2 parents a0c0c00 + 316a9fd commit da254fe
Show file tree
Hide file tree
Showing 28 changed files with 1,549 additions and 948 deletions.
31 changes: 20 additions & 11 deletions neomodel/async_/cardinality.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from typing import TYPE_CHECKING, Any, Optional

from neomodel.async_.relationship_manager import ( # pylint:disable=unused-import
AsyncRelationshipManager,
AsyncZeroOrMore,
)
from neomodel.exceptions import AttemptedCardinalityViolation, CardinalityViolation

if TYPE_CHECKING:
from neomodel import AsyncStructuredNode, AsyncStructuredRel


class AsyncZeroOrOne(AsyncRelationshipManager):
"""A relationship to zero or one node."""

description = "zero or one relationship"

async def single(self):
async def single(self) -> Optional["AsyncStructuredNode"]:
"""
Return the associated node.
Expand All @@ -23,11 +28,13 @@ async def single(self):
raise CardinalityViolation(self, len(nodes))
return None

async def all(self):
async def all(self) -> list["AsyncStructuredNode"]:
node = await self.single()
return [node] if node else []

async def connect(self, node, properties=None):
async def connect(
self, node: "AsyncStructuredNode", properties: Optional[dict[str, Any]] = None
) -> "AsyncStructuredRel":
"""
Connect to a node.
Expand All @@ -49,7 +56,7 @@ class AsyncOneOrMore(AsyncRelationshipManager):

description = "one or more relationships"

async def single(self):
async def single(self) -> "AsyncStructuredNode":
"""
Fetch one of the related nodes
Expand All @@ -60,7 +67,7 @@ async def single(self):
return nodes[0]
raise CardinalityViolation(self, "none")

async def all(self):
async def all(self) -> list["AsyncStructuredNode"]:
"""
Returns all related nodes.
Expand All @@ -71,7 +78,7 @@ async def all(self):
return nodes
raise CardinalityViolation(self, "none")

async def disconnect(self, node):
async def disconnect(self, node: "AsyncStructuredNode") -> None:
"""
Disconnect node
:param node:
Expand All @@ -89,7 +96,7 @@ class AsyncOne(AsyncRelationshipManager):

description = "one relationship"

async def single(self):
async def single(self) -> "AsyncStructuredNode":
"""
Return the associated node.
Expand All @@ -102,25 +109,27 @@ async def single(self):
raise CardinalityViolation(self, len(nodes))
raise CardinalityViolation(self, "none")

async def all(self):
async def all(self) -> list["AsyncStructuredNode"]:
"""
Return single node in an array
:return: [node]
"""
return [await self.single()]

async def disconnect(self, node):
async def disconnect(self, node: "AsyncStructuredNode") -> None:
raise AttemptedCardinalityViolation(
"Cardinality one, cannot disconnect use reconnect."
)

async def disconnect_all(self):
async def disconnect_all(self) -> None:
raise AttemptedCardinalityViolation(
"Cardinality one, cannot disconnect_all use reconnect."
)

async def connect(self, node, properties=None):
async def connect(
self, node: "AsyncStructuredNode", properties: Optional[dict[str, Any]] = None
) -> "AsyncStructuredRel":
"""
Connect a node
Expand Down
Loading

0 comments on commit da254fe

Please sign in to comment.