add more types

This commit is contained in:
2024-08-08 21:19:43 +02:00
parent a5ac10b20d
commit 25deac6ea9
4 changed files with 66 additions and 53 deletions

View File

@ -12,7 +12,7 @@ def _safe_timedelta(duration: timedelta | int | None):
def format_duration(
duration: timedelta | int | None, format_string: str = "%H hours"
duration: timedelta | int | float | None, format_string: str = "%H hours"
) -> str:
"""
Format timedelta into the specified format_string.

View File

@ -1,3 +1,6 @@
from typing import Any
def safe_division(numerator: int | float, denominator: int | float) -> int | float:
"""
Divides without triggering division by zero exception.
@ -9,7 +12,7 @@ def safe_division(numerator: int | float, denominator: int | float) -> int | flo
return 0
def safe_getattr(obj, attr_chain, default=None):
def safe_getattr(obj: object, attr_chain: str, default: Any | None = None) -> object:
"""
Safely get the nested attribute from an object.