From d12e2fa8930a82be4e96fa359d9e96a03245973f Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sat, 16 Apr 2022 10:46:07 +0800 Subject: [PATCH 1/2] Add type definitions for item() --- tomlkit/items.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tomlkit/items.py b/tomlkit/items.py index 9c11934..dba2631 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -9,7 +9,7 @@ from datetime import tzinfo from enum import Enum from functools import lru_cache -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Sequence from typing import Any from typing import Collection from typing import Dict @@ -58,6 +58,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": From bf3a3f5cf29ea0cd623d609385da91215fad826e Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sat, 16 Apr 2022 10:49:50 +0800 Subject: [PATCH 2/2] import on its own line --- CHANGELOG.md | 5 ++++- tomlkit/items.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 dba2631..bdc97f2 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -9,7 +9,7 @@ from datetime import tzinfo from enum import Enum from functools import lru_cache -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING from typing import Any from typing import Collection from typing import Dict @@ -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