diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a9acfb..a923f3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ ## [Unreleased] -- Fix the `astimezone()` and `replace()` methods of datetime objects. ([#188](https://github.com/sdispater/tomlkit/issues/178)) +### Fixed + +- Fix the `astimezone()` and `replace()` methods of datetime objects. ([#188](https://github.com/sdispater/tomlkit/issues/188)) +- Add type definitions for `items()` function. ([#190](https://github.com/sdispater/tomlkit/issues/190)) ## [0.10.1] - 2022-03-27 diff --git a/tomlkit/items.py b/tomlkit/items.py index 9c11934..bdc97f2 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -17,6 +17,7 @@ from typing import Iterator from typing import List from typing import Optional +from typing import Sequence from typing import TypeVar from typing import Union from typing import cast @@ -58,6 +59,71 @@ class _CustomDict(MutableMapping, dict): """Adds MutableMapping mixin while pretending to be a builtin dict""" +ItemT = TypeVar("ItemT", bound="Item") + + +@overload +def item(value: bool) -> "Bool": + ... + + +@overload +def item(value: int) -> "Integer": + ... + + +@overload +def item(value: float) -> "Float": + ... + + +@overload +def item(value: str) -> "String": + ... + + +@overload +def item(value: datetime) -> "DateTime": + ... + + +@overload +def item(value: date) -> "Date": + ... + + +@overload +def item(value: time) -> "Time": + ... + + +@overload +def item(value: Sequence[dict]) -> "AoT": + ... + + +@overload +def item(value: Sequence) -> "Array": + ... + + +@overload +def item(value: dict, _parent: "Array" = ..., _sort_keys: bool = ...) -> "InlineTable": + ... + + +@overload +def item( + value: dict, _parent: Optional["Item"] = ..., _sort_keys: bool = ... +) -> "Table": + ... + + +@overload +def item(value: ItemT) -> ItemT: + ... + + def item( value: Any, _parent: Optional["Item"] = None, _sort_keys: bool = False ) -> "Item":