-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ship py.typed to allow type checking
The py.typed needs to be present in the module to make type checking work (see PEP 561). In order to make it possible, the module can no longer be a single file, but needs to be installed in a directory.
- Loading branch information
Showing
5 changed files
with
44 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .exceptions import ThrottlingError | ||
from .fiobank import FioBank | ||
|
||
|
||
__all__ = ("FioBank", "ThrottlingError") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class ThrottlingError(Exception): | ||
"""Throttling error raised when the API is being used too fast.""" | ||
|
||
def __str__(self) -> str: | ||
return "Token can be used only once per 30s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import date, datetime | ||
from decimal import Decimal | ||
from typing import Any, Callable | ||
|
||
|
||
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) -> date: | ||
if isinstance(value, datetime): | ||
return value.date() | ||
if isinstance(value, date): | ||
return value | ||
return datetime.strptime(value[:10], "%Y-%m-%d").date() | ||
|
||
|
||
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: | ||
return convert(value) | ||
return value |