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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type definitions for item() #190

Merged
merged 2 commits into from Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand Down
66 changes: 66 additions & 0 deletions tomlkit/items.py
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down