Skip to content

Commit 5c98124

Browse files
authored
Merge pull request #6550 from opsmill/pog-standard-node-typing
Typing for standard node
2 parents 5d11893 + 9598afa commit 5c98124

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

backend/infrahub/core/query/standard_node.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,42 @@
33
from typing import TYPE_CHECKING, Any
44

55
from infrahub.core.query import Query, QueryType
6+
from infrahub.exceptions import InitializationError
67

78
if TYPE_CHECKING:
9+
from uuid import UUID
10+
811
from infrahub.core.node.standard import StandardNode
912
from infrahub.database import InfrahubDatabase
1013

1114

1215
class StandardNodeQuery(Query):
1316
def __init__(
14-
self, node: StandardNode = None, node_id: str | None = None, node_db_id: int | None = None, **kwargs: Any
15-
):
16-
self.node = node
17+
self,
18+
node: StandardNode | None = None,
19+
node_id: UUID | None = None,
20+
node_db_id: str | None = None,
21+
**kwargs: Any,
22+
) -> None:
23+
self._node = node
1724
self.node_id = node_id
1825
self.node_db_id = node_db_id
1926

20-
if not self.node_id and self.node:
27+
if not self.node_id and self._node:
2128
self.node_id = self.node.uuid
2229

23-
if not self.node_db_id and self.node:
30+
if not self.node_db_id and self._node:
2431
self.node_db_id = self.node.id
2532

2633
super().__init__(**kwargs)
2734

35+
@property
36+
def node(self) -> StandardNode:
37+
if self._node:
38+
return self._node
39+
40+
raise InitializationError("The query is not initialized with a node")
41+
2842

2943
class RootNodeCreateQuery(StandardNodeQuery):
3044
name = "standard_node_create"

pyproject.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@ disable_error_code = [
291291
"var-annotated",
292292
]
293293

294-
[[tool.mypy.overrides]]
295-
module = "infrahub.core.query.standard_node"
296-
disable_error_code = [
297-
"arg-type",
298-
"assignment",
299-
]
300-
301294
[[tool.mypy.overrides]]
302295
module = "infrahub.core.query.subquery"
303296
disable_error_code = [

0 commit comments

Comments
 (0)