improve typing
This commit is contained in:
parent
0bd0d7c862
commit
2ab9ca5456
1 changed files with 5 additions and 3 deletions
|
|
@ -12,11 +12,13 @@ DEFAULT_MONEY_PRECISION = Decimal(
|
|||
|
||||
|
||||
class MoneyAmount:
|
||||
def __init__(self, amount, currency):
|
||||
def __init__(
|
||||
self, amount: Union[int, Decimal, str], currency: Union[str, Currency]
|
||||
) -> "MoneyAmount":
|
||||
self.amount = self._parse_amount(amount)
|
||||
self.currency = self._parse_currency(currency)
|
||||
|
||||
def _parse_amount(self, amount: Union[int, Decimal, str]):
|
||||
def _parse_amount(self, amount: Union[int, Decimal, str]) -> Decimal:
|
||||
if isinstance(amount, (int, Decimal)):
|
||||
return Decimal(amount).quantize(DEFAULT_MONEY_PRECISION)
|
||||
elif isinstance(amount, str):
|
||||
|
|
@ -27,7 +29,7 @@ class MoneyAmount:
|
|||
else:
|
||||
raise TypeError(f"Amount must be int, Decimal, or str, not {type(amount)}")
|
||||
|
||||
def _parse_currency(self, currency):
|
||||
def _parse_currency(self, currency: Union[str, Currency]) -> Currency:
|
||||
if isinstance(currency, Currency):
|
||||
return currency
|
||||
if isinstance(currency, str):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue