You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/python-sdk/guides/python-typing.mdx
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ This guide explains how to use Python's type system effectively with the Infrahu
9
9
:::note What is Python Typing
10
10
11
11
Python typing allows you to specify the expected data types of variables, function arguments, and return values to improve code clarity and catch bugs early.
The Python SDK for Infrahub has been designed to automatically work with any schemas loaded into Infrahub.
23
+
The Python SDK for Infrahub has been designed to automatically work with any schemas loaded into Infrahub.
23
24
Internally, the Python SDK generates dynamic Python representations of your schemas.
24
25
25
26
While this approach improves code readability, it presents challenges with type checking because each object has a different signature based on your schema.
26
27
27
-
### Without Protocols
28
+
### Without protocols
28
29
29
30
In the example below, type checkers like Mypy will typically complain about `blue_tag.description.value` because `description` is a dynamic parameter generated by the SDK.
30
31
@@ -35,7 +36,7 @@ blue_tag.description.value = "The blue tag" # Mypy: error: "InfrahubNode" has n
35
36
blue_tag.save()
36
37
```
37
38
38
-
### With Protocols
39
+
### With protocols
39
40
40
41
To provide strict type checking while maintaining platform extensibility, the Python SDK integrates with Python Protocols.
41
42
@@ -57,7 +58,7 @@ Python Protocols, introduced in PEP 544, define a set of method and property sig
57
58
58
59
:::
59
60
60
-
## Generating Custom Protocols based on your schema
61
+
## Generating custom protocols based on your schema
61
62
62
63
You can generate Python Protocols for your own models using the `infrahubctl protocols` command. This supports both synchronous and asynchronous Python code.
0 commit comments