Skip to content

Commit

Permalink
Initial stub (#686)
Browse files Browse the repository at this point in the history
* Initial stub

* Add get_current_locale() to typing

* __div__ and __mul__ works with numerical types

* Bump used mypy version

* Fix typing and CI env

* Cater to black's nazism

* Ignore DeprecationWarning-s from pkg_resources
  • Loading branch information
karolyi committed Apr 20, 2023
1 parent b579017 commit 4737396
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ repos:
exclude: ^docs

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.981
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies:
- django-stubs
- py-moneyed
files: 'djmoney\/.*\.py|tests\/.*\.py'
exclude: djmoney/money.py
62 changes: 62 additions & 0 deletions djmoney/money.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from decimal import Decimal
from typing import Any, Optional, Union, overload, type_check_only

from django.db.models.expressions import CombinedExpression, F
from django.utils.safestring import SafeText

from typing_extensions import Literal, TypedDict

from moneyed import Currency, Money as _DefaultMoney

__all__ = ["Money", "Currency"]
DefaultMoney = _DefaultMoney

@type_check_only
class _FormatOptions(TypedDict):
"Format options parameter."
format: Optional[str]
locale: str
currency_digits: bool
format_type: Literal["standard", "standard:short", "name"]
decimal_quantization: bool

class Money(DefaultMoney):
use_l10n: Any
decimal_places: Any
format_options: Any

def __init__(self, *args, format_options: Optional[_FormatOptions] = ..., **kwargs) -> None: ...
@overload # type: ignore[override]
def __add__(self, other: Money) -> Money: ...
@overload
def __add__(self, other: F) -> CombinedExpression: ...
@overload # type: ignore[override]
def __sub__(self, other: Money) -> Money: ...
@overload
def __sub__(self, other: F) -> CombinedExpression: ...
@overload # type: ignore[override]
def __mul__(self, other: _NumericalType) -> Money: ...
@overload
def __mul__(self, other: F) -> CombinedExpression: ...
@overload # type: ignore[override]
def __truediv__(self, other: _NumericalType) -> Money: ...
@overload
def __truediv__(self, other: F) -> CombinedExpression: ...
def __rtruediv__(self, other) -> None: ... # type: ignore[override]
@property
def is_localized(self) -> bool: ...
def __html__(self) -> SafeText: ...
def __round__(self, n: Any | None = ...) -> Money: ...
def round(self, ndigits: int = ...) -> Money: ... # type: ignore[override]
def __pos__(self) -> Money: ...
def __neg__(self) -> Money: ...
def __abs__(self) -> Money: ...
def __rmod__(self, other) -> Money: ...
def __radd__(self, other) -> Money: ... # type: ignore[override]
def __rmul__(self, other) -> Money: ... # type: ignore[override]

def get_current_locale() -> str: ...

_NumericalType = Union[Decimal, float, int]
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
DJANGO_SETTINGS_MODULE=tests.settings
filterwarnings =
error::DeprecationWarning
ignore:pkg_resources is deprecated as an API:DeprecationWarning
addopts = "--no-cov-on-fail"

0 comments on commit 4737396

Please sign in to comment.