Skip to content

Commit

Permalink
chore: Fix various small mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
klette committed Apr 22, 2024
1 parent 895f8b6 commit 35d19f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/moneyed/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def name(self) -> str:
def get_name(self, locale: str, count: int | None = None) -> str:
from babel.numbers import get_currency_name

return get_currency_name( # type: ignore[no-any-return]
return get_currency_name(
self.code,
locale=locale,
count=count,
Expand Down Expand Up @@ -254,6 +254,13 @@ def __mul__(self: M, other: object) -> M:
currency=self.currency,
)


@overload
def __truediv__(self: M, other: int|float|Decimal) -> M:
...
@overload
def __truediv__(self: M, other: Money) -> Decimal:
...
def __truediv__(self: M, other: object) -> M | Decimal:
if isinstance(other, Money):
if self.currency != other.currency:
Expand Down
8 changes: 5 additions & 3 deletions src/moneyed/l10n.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing_extensions import Literal

from babel import Locale
from babel.numbers import LC_NUMERIC
from babel.numbers import format_currency as babel_format_currency

Expand All @@ -12,15 +14,15 @@
def format_money(
money: Money,
format: str | None = None,
locale: str = LC_NUMERIC,
locale: Locale | str | None = LC_NUMERIC,
currency_digits: bool = True,
format_type: str = "standard",
format_type: Literal["name", "standard", "accounting"] = "standard",
decimal_quantization: bool = True,
) -> str:
"""
See https://babel.pocoo.org/en/latest/api/numbers.html
"""
return babel_format_currency( # type: ignore[no-any-return]
return babel_format_currency(
money.amount,
money.currency.code,
format=format,
Expand Down

0 comments on commit 35d19f4

Please sign in to comment.