Formatting
All checks were successful
Django CI/CD / test (push) Successful in 1m21s
Django CI/CD / build-and-push (push) Successful in 1m57s

This commit is contained in:
2024-06-03 18:19:11 +02:00
parent cd804f2c77
commit 44c70a5ee7
3 changed files with 7 additions and 3 deletions

View File

@ -7,7 +7,8 @@ def safe_division(numerator: int | float, denominator: int | float) -> int | flo
return numerator / denominator
except ZeroDivisionError:
return 0
def safe_getattr(obj, attr_chain, default=None):
"""
Safely get the nested attribute from an object.
@ -20,7 +21,7 @@ def safe_getattr(obj, attr_chain, default=None):
Returns:
The value of the nested attribute if it exists, otherwise the default value.
"""
attrs = attr_chain.split('.')
attrs = attr_chain.split(".")
for attr in attrs:
try:
obj = getattr(obj, attr)