Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悜 Add seperate typing hints for humanize #150

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -38,3 +38,8 @@ repos:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,2 @@
include src/humanize/py.typed
include src/humanize/*.pyi
hugovk marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions src/humanize/__init__.pyi
@@ -0,0 +1,7 @@
from humanize.filesize import naturalsize as naturalsize
from humanize.i18n import activate as activate, deactivate as deactivate
from humanize.number import apnumber as apnumber, fractional as fractional, intcomma as intcomma, intword as intword, ordinal as ordinal, scientific as scientific
from humanize.time import naturaldate as naturaldate, naturalday as naturalday, naturaldelta as naturaldelta, naturaltime as naturaltime, precisedelta as precisedelta

VERSION: str
__version__: str
2 changes: 1 addition & 1 deletion src/humanize/filesize.py
Expand Up @@ -5,7 +5,7 @@
suffixes = {
"decimal": ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"),
"binary": ("KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"),
"gnu": "KMGTPEZY",
"gnu": ("K", "M", "G", "T", "P", "E", "Z", "Y"),
hugovk marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
10 changes: 10 additions & 0 deletions src/humanize/filesize.pyi
@@ -0,0 +1,10 @@
from typing import Any, Dict, SupportsFloat, Tuple, Union

suffixes: Dict[str, Tuple[str, ...]]

def naturalsize(
value: Union[str, SupportsFloat],
binary: bool = ...,
gnu: bool = ...,
format: str = ...
) -> str: ...
6 changes: 6 additions & 0 deletions src/humanize/i18n.pyi
@@ -0,0 +1,6 @@
from typing import Any, Dict, Optional

def activate(locale: str, path: Optional[str] = ...) -> Dict[Any, Any]: ...
def deactivate() -> None: ...
def gettext(message: str) -> str: ...
def ngettext(message: str, plural: str, num: str) -> str: ...
12 changes: 12 additions & 0 deletions src/humanize/number.pyi
@@ -0,0 +1,12 @@
from typing import Any, List, SupportsInt, SupportsFloat, Tuple, Union, Optional

def ordinal(value: Union[str, SupportsInt]) -> str: ...
hugovk marked this conversation as resolved.
Show resolved Hide resolved
def intcomma(value: Union[str, SupportsFloat], ndigits: Optional[int] = ...): ...

powers: List[int]
human_powers: Tuple[str, ...]

def intword(value: Union[str, SupportsInt], format: str = ...) -> str: ...
def apnumber(value: Union[str, SupportsInt]) -> str: ...
def fractional(value: Union[str, SupportsFloat]) -> str: ...
def scientific(value: Union[str, SupportsFloat], precision: int = ...) -> str: ...
Empty file added src/humanize/py.typed
Empty file.
41 changes: 41 additions & 0 deletions src/humanize/time.pyi
@@ -0,0 +1,41 @@
from datetime import date, datetime, timedelta
from enum import Enum
from typing import Any, Iterable, Literal, Union

class Unit(Enum):
MICROSECONDS: int = ...
MILLISECONDS: int = ...
SECONDS: int = ...
MINUTES: int = ...
HOURS: int = ...
DAYS: int = ...
MONTHS: int = ...
YEARS: int = ...
def __lt__(self, other: Any) -> Any: ...

def naturaldelta(
value: Union[timedelta, int],
months: bool = ...,
minimum_unit: Literal["seconds", "milliseconds", "microseconds"] = ...
) -> str: ...

def naturaltime(
value: Union[datetime, int],
future: bool = ...,
months: bool = ...,
minimum_unit: Literal["seconds", "milliseconds", "microseconds"] = ...
) -> str: ...

def naturalday(
value: Union[date, datetime],
format: str = ...
) -> str: ...

def naturaldate(value: Union[date, datetime]) -> str: ...

def precisedelta(
value: Union[timedelta, int],
minimum_unit: Literal["microseconds", "milliseconds", "seconds", "minutes", "hours", "days", "months", "years"] = ...,
suppress: Iterable[Literal["microseconds", "milliseconds", "seconds", "minutes", "hours", "days", "months", "years"]] = ...,
format: str = ...
) -> str: ...