From cce8f99ea283c7b6fb3537cc7586166b0a64e74b Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Wed, 4 Sep 2024 18:00:34 -0700 Subject: [PATCH] feat: added type annotation --- CHANGES.md | 2 ++ MANIFEST.in | 1 + src/py.typed | 0 src/unflatten.pyi | 16 ++++++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 src/py.typed create mode 100644 src/unflatten.pyi diff --git a/CHANGES.md b/CHANGES.md index 3da5742..aef91f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,8 @@ ### Release 0.1.2 (unreleased) +- Added type annotations. + #### Testing - Test under python 3.10, 3.11, and 3.12. diff --git a/MANIFEST.in b/MANIFEST.in index b74c9b5..988557b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,4 +5,5 @@ prune .github # these are redundant, as setuptools-scm includes everything in the git repo include LICENSE.txt README.md CHANGES.md include tox.ini +include src/unflatten.pyi src/py.typed recursive-include tests *.py diff --git a/src/py.typed b/src/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/unflatten.pyi b/src/unflatten.pyi new file mode 100644 index 0000000..0789d83 --- /dev/null +++ b/src/unflatten.pyi @@ -0,0 +1,16 @@ +from typing import Mapping +from typing import overload +from typing import Sequence +from typing import TypeAlias +from typing import TypeVar + +_T = TypeVar("_T") + +Unflattened: TypeAlias = dict[ + str, _T | "Unflattened[_T]" | list[_T | "Unflattened[_T]"] +] + +@overload +def unflatten(arg: Mapping[str, _T]) -> Unflattened[_T]: ... +@overload +def unflatten(arg: Sequence[tuple[str, _T]]) -> Unflattened[_T]: ...