Skip to content

Commit 97dbf0e

Browse files
committed
Add more details to the docstring
1 parent 9edaf7a commit 97dbf0e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

infrahub_sdk/template/filters.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def value_to_enum_name(value: Any, enum_path: str | None = None) -> str:
1515
"""Convert a value to its enum member name using the specified enum class.
1616
1717
This filter takes a raw value and converts it to the corresponding enum member name by dynamically importing the
18-
enum class.
18+
enum class if provided. The enum class can be any valid enum as long as its full import path is given.
1919
20-
For example, `{{ decision__value | value_to_enum_name("infrahub.core.constants.PermissionDecision") }}`
21-
will return: `"ALLOW_ALL"` for value `6`.
20+
If the value is already an instance of `Enum` and no `enum_path` is provided, it simply returns the name of the
21+
enum member which is equivalent to using `{{ value.name }}` in a Jinja2 template.
22+
23+
Usage example: `{{ decision__value | value_to_enum_name("infrahub.core.constants.PermissionDecision") }}` will return `"ALLOW_ALL"` for value `6`.
2224
"""
2325
if isinstance(value, Enum) and not enum_path:
2426
return value.name

0 commit comments

Comments
 (0)