Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions stubs/toml/@tests/stubtest_allowlist.txt

This file was deleted.

19 changes: 0 additions & 19 deletions stubs/toml/toml.pyi

This file was deleted.

16 changes: 16 additions & 0 deletions stubs/toml/toml/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from . import decoder as decoder, encoder as encoder

load = decoder.load
loads = decoder.loads
TomlDecoder = decoder.TomlDecoder
TomlDecodeError = decoder.TomlDecodeError
TomlPreserveCommentDecoder = decoder.TomlPreserveCommentDecoder

dump = encoder.dump
dumps = encoder.dumps
TomlEncoder = encoder.TomlEncoder
TomlArraySeparatorEncoder = encoder.TomlArraySeparatorEncoder
TomlPreserveInlineDictEncoder = encoder.TomlPreserveInlineDictEncoder
TomlNumpyEncoder = encoder.TomlNumpyEncoder
TomlPreserveCommentEncoder = encoder.TomlPreserveCommentEncoder
TomlPathlibEncoder = encoder.TomlPathlibEncoder
78 changes: 78 additions & 0 deletions stubs/toml/toml/decoder.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sys
from _typeshed import StrPath
from typing import IO, Callable, Generic, MutableMapping, Pattern, Protocol, Text, TypeVar

_T = TypeVar("_T")
_KT_contra = TypeVar("_KT_contra", contravariant=True)
_VT = TypeVar("_VT")

if sys.version_info >= (3, 3):
FNFError = FileNotFoundError
else:
FNFError = IOError

if sys.version_info >= (3, 6):
_PathLike = StrPath
elif sys.version_info >= (3, 4):
import pathlib

_PathLike = StrPath | pathlib.PurePath
else:
_PathLike = StrPath

class _SupportsGetSetItem(Protocol[_KT_contra, _VT]):
def __getitem__(self, __k: _KT_contra) -> _VT: ...
def __setitem__(self, __k: _KT_contra, __v: _VT) -> None: ...

TIME_RE: Pattern[str]

class TomlDecodeError(ValueError):
msg: str
doc: str
pos: int
lineno: int
colno: int
def __init__(self, msg: str, doc: str, pos: int) -> None: ...

class CommentValue(_SupportsGetSetItem[_KT_contra, _VT]):
val: _SupportsGetSetItem[_KT_contra, _VT]
comment: str
def __init__(
self,
val: _SupportsGetSetItem[_KT_contra, _VT],
comment: str,
beginline: bool,
_dict: type[MutableMapping[_KT_contra, _VT]],
) -> None: ...
def __getitem__(self, key: _KT_contra) -> _VT: ...
def __setitem__(self, key: _KT_contra, value: _VT) -> None: ...
def dump(self, dump_value_func: Callable[[_SupportsGetSetItem[_KT_contra, _VT]], str]) -> str: ...

def load(
f: _PathLike | list[Text] | IO[str], _dict: type[MutableMapping[str, _T]] = ..., decoder: TomlDecoder[_T] | None = ...
) -> MutableMapping[str, _T]: ...
def loads(
s: Text, _dict: type[MutableMapping[str, _T]] = ..., decoder: TomlDecoder[_T] | None = ...
) -> MutableMapping[str, _T]: ...

class InlineTableDict: ...

class TomlDecoder(Generic[_T]):
_dict: type[MutableMapping[str, _T]]
def __init__(self, _dict: type[MutableMapping[str, _T]] | None = ...) -> None: ...
def get_empty_table(self) -> MutableMapping[str, _T]: ...
def get_empty_inline_table(self) -> InlineTableDict: ... # incomplete python/typing#213
def load_inline_object(
self, line: str, currentlevel: MutableMapping[str, _T], multikey: bool = ..., multibackslash: bool = ...
) -> None: ...
def load_line(
self, line: str, currentlevel: MutableMapping[str, _T], multikey: bool | None, multibackslash: bool
) -> tuple[bool | None, str, bool] | None: ...
def load_value(self, v: str, strictly_valid: bool = ...) -> tuple[bool, str]: ...
def bounded_string(self, s: str) -> bool: ...
def load_array(self, a: str) -> list[_T]: ...
def preserve_comment(self, line_no: int, key: str, comment: str, beginline: bool) -> None: ...
def embed_comments(self, idx: int, currentlevel: MutableMapping[str, _T]) -> None: ...

class TomlPreserveCommentDecoder(TomlDecoder[_T]):
saved_comments: MutableMapping[int, tuple[str, str, bool]]
28 changes: 28 additions & 0 deletions stubs/toml/toml/encoder.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from _typeshed import SupportsWrite
from typing import Any, Callable, Iterable, Mapping, MutableMapping

def dump(o: Mapping[str, Any], f: SupportsWrite[str], encoder: TomlEncoder | None = ...) -> str: ...
def dumps(o: Mapping[str, Any], encoder: TomlEncoder | None = ...) -> str: ...

class TomlEncoder:
_dict: type[Mapping[str, Any]]
preserve: bool
dump_funcs: MutableMapping[type[Any], Callable[[Any], str]]
def __init__(self, _dict: type[Mapping[str, Any]] = ..., preserve: bool = ...) -> None: ...
def get_empty_table(self) -> Mapping[str, Any]: ...
def dump_list(self, v: Iterable[object]) -> str: ...
def dump_inline_table(self, section: dict[str, Any] | Any) -> str: ...
def dump_value(self, v: Any) -> str: ...
def dump_sections(self, o: Mapping[str, Any], sup: str) -> tuple[str, Mapping[str, Any]]: ...

class TomlPreserveInlineDictEncoder(TomlEncoder):
def __init__(self, _dict: type[Mapping[str, Any]] = ...) -> None: ...

class TomlArraySeparatorEncoder(TomlEncoder):
separator: str
def __init__(self, _dict: type[Mapping[str, Any]] = ..., preserve: bool = ..., separator: str = ...) -> None: ...
def dump_list(self, v: Iterable[Any]) -> str: ...

class TomlNumpyEncoder(TomlEncoder): ...
class TomlPreserveCommentEncoder(TomlEncoder): ...
class TomlPathlibEncoder(TomlEncoder): ...
12 changes: 12 additions & 0 deletions stubs/toml/toml/ordered.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import TypeVar

from .decoder import TomlDecoder
from .encoder import TomlEncoder

_T = TypeVar("_T")

class TomlOrderedDecoder(TomlDecoder[_T]):
def __init__(self) -> None: ...

class TomlOrderedEncoder(TomlEncoder):
def __init__(self) -> None: ...
9 changes: 9 additions & 0 deletions stubs/toml/toml/tz.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from datetime import datetime, timedelta, tzinfo
from typing import Any

class TomlTz(tzinfo):
def __init__(self, toml_offset: str) -> None: ...
def __deepcopy__(self, memo: Any) -> TomlTz: ...
def tzname(self, dt: datetime | None) -> str | None: ...
def utcoffset(self, dt: datetime | None) -> timedelta | None: ...
def dst(self, dt: datetime | None) -> timedelta | None: ...