Skip to content

Commit

Permalink
union type by | exists only since Python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Dec 28, 2024
1 parent c7d2339 commit e32a00f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions fiobank.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
__all__ = ("FioBank", "ThrottlingError")


def coerce_amount(value: int | float) -> Decimal:
def coerce_amount(value: "int | float") -> Decimal:
if isinstance(value, int):
return Decimal(value)
if isinstance(value, float):
return Decimal(str(value))
raise ValueError(value)


def coerce_date(value: datetime | date | str):
def coerce_date(value: "datetime | date | str") -> date:
if isinstance(value, datetime):
return value.date()
elif isinstance(value, date):
Expand All @@ -33,7 +33,7 @@ def coerce_date(value: datetime | date | str):
return datetime.strptime(value[:10], "%Y-%m-%d").date()


def sanitize_value(value: Any, convert: Callable | None = None) -> Any:
def sanitize_value(value: Any, convert: "Callable | None" = None) -> Any:
if isinstance(value, str):
value = value.strip() or None
if convert and value is not None:
Expand Down Expand Up @@ -199,7 +199,7 @@ def info(self) -> dict:
raise ValueError("No data available")

def period(
self, from_date: date | datetime | str, to_date: date | datetime | str
self, from_date: "date | datetime | str", to_date: "date | datetime | str"
) -> Generator[dict, None, None]:
if data := self._request(
"periods", from_date=coerce_date(from_date), to_date=coerce_date(to_date)
Expand All @@ -213,7 +213,9 @@ def statement(self, year: int, number: int) -> Generator[dict, None, None]:
raise ValueError("No data available")

def last(
self, from_id: int | None = None, from_date: date | datetime | str | None = None
self,
from_id: "int | None" = None,
from_date: "date | datetime | str | None" = None,
) -> Generator[dict, None, None]:
if from_id and from_date:
raise ValueError("Only one constraint is allowed.")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coerce_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"2016-08-03T21:03:42",
],
)
def test_coerce_date(test_input: date | datetime | str):
def test_coerce_date(test_input: "date | datetime | str"):
assert coerce_date(test_input) == date(2016, 8, 3)


@pytest.mark.parametrize("test_input", [42, True])
def test_coerce_date_invalid_type(test_input: int | bool):
def test_coerce_date_invalid_type(test_input: "int | bool"):
with pytest.raises(TypeError):
coerce_date(test_input) # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sanitize_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_sanitize_value_no_effect(test_input: Any, expected: Any):
("\nfio ", "fio"),
],
)
def test_sanitize_value_strip(test_input: str, expected: str | None):
def test_sanitize_value_strip(test_input: str, expected: "str | None"):
assert sanitize_value(test_input) == expected


Expand Down

0 comments on commit e32a00f

Please sign in to comment.