Skip to content

Commit 352de24

Browse files
authored
Add type definitions for item() (#190)
1 parent 5118514 commit 352de24

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## [Unreleased]
44

5-
- Fix the `astimezone()` and `replace()` methods of datetime objects. ([#188](https://github.com/sdispater/tomlkit/issues/178))
5+
### Fixed
6+
7+
- Fix the `astimezone()` and `replace()` methods of datetime objects. ([#188](https://github.com/sdispater/tomlkit/issues/188))
8+
- Add type definitions for `items()` function. ([#190](https://github.com/sdispater/tomlkit/issues/190))
69

710
## [0.10.1] - 2022-03-27
811

tomlkit/items.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Iterator
1818
from typing import List
1919
from typing import Optional
20+
from typing import Sequence
2021
from typing import TypeVar
2122
from typing import Union
2223
from typing import cast
@@ -58,6 +59,71 @@ class _CustomDict(MutableMapping, dict):
5859
"""Adds MutableMapping mixin while pretending to be a builtin dict"""
5960

6061

62+
ItemT = TypeVar("ItemT", bound="Item")
63+
64+
65+
@overload
66+
def item(value: bool) -> "Bool":
67+
...
68+
69+
70+
@overload
71+
def item(value: int) -> "Integer":
72+
...
73+
74+
75+
@overload
76+
def item(value: float) -> "Float":
77+
...
78+
79+
80+
@overload
81+
def item(value: str) -> "String":
82+
...
83+
84+
85+
@overload
86+
def item(value: datetime) -> "DateTime":
87+
...
88+
89+
90+
@overload
91+
def item(value: date) -> "Date":
92+
...
93+
94+
95+
@overload
96+
def item(value: time) -> "Time":
97+
...
98+
99+
100+
@overload
101+
def item(value: Sequence[dict]) -> "AoT":
102+
...
103+
104+
105+
@overload
106+
def item(value: Sequence) -> "Array":
107+
...
108+
109+
110+
@overload
111+
def item(value: dict, _parent: "Array" = ..., _sort_keys: bool = ...) -> "InlineTable":
112+
...
113+
114+
115+
@overload
116+
def item(
117+
value: dict, _parent: Optional["Item"] = ..., _sort_keys: bool = ...
118+
) -> "Table":
119+
...
120+
121+
122+
@overload
123+
def item(value: ItemT) -> ItemT:
124+
...
125+
126+
61127
def item(
62128
value: Any, _parent: Optional["Item"] = None, _sort_keys: bool = False
63129
) -> "Item":

0 commit comments

Comments
 (0)