-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve toml
typings
#7146
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
Merged
Merged
Improve toml
typings
#7146
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
45a9ebe
Improve `toml` typings
9f58b5f
Fix linting and stubtest test for `toml`
380b556
Fix type hints in `toml.decoder` and `toml.tz`
faresbakhit 1385178
Improve `toml` API type hints
1df36e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e3d55e4
Merge branch 'python:master' into master
faresbakhit 0daae1a
Merge branch 'python:master' into master
faresbakhit 715bd67
Fix types in `toml.decoder` and `toml.encoder`
733c6fa
Fix `toml.ordered` types
3095624
Merge branch 'python:master' into master
faresbakhit c0edc30
Apply suggestions for `toml`
faresbakhit ec6f19c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 218a3ca
Improve `toml`'s type hints
d109e4c
use `collections.OrderedDict` instead of `typing.OrderedDict`
249edbb
Improve `toml.decoder.TomlPreserveCommentDecoder.saved_comments` type
faresbakhit be37372
Improve overloads order in `toml`
1caa312
Improve types exporting in `toml.__init__`
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from . import decoder as decoder, encoder as encoder | ||
from .decoder import ( | ||
TomlDecodeError as TomlDecodeError, | ||
TomlDecoder as TomlDecoder, | ||
TomlPreserveCommentDecoder as TomlPreserveCommentDecoder, | ||
load as load, | ||
loads as loads, | ||
) | ||
from .encoder import ( | ||
TomlArraySeparatorEncoder as TomlArraySeparatorEncoder, | ||
TomlEncoder as TomlEncoder, | ||
TomlNumpyEncoder as TomlNumpyEncoder, | ||
TomlPathlibEncoder as TomlPathlibEncoder, | ||
TomlPreserveCommentEncoder as TomlPreserveCommentEncoder, | ||
TomlPreserveInlineDictEncoder as TomlPreserveInlineDictEncoder, | ||
dump as dump, | ||
dumps as dumps, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import sys | ||
from _typeshed import SupportsRead | ||
from typing import Any, Callable, Generic, MutableMapping, Pattern, Text, TypeVar, overload | ||
|
||
_MutableMappingT = TypeVar("_MutableMappingT", bound=MutableMapping[str, Any]) | ||
|
||
if sys.version_info >= (3, 0): | ||
from pathlib import PurePath | ||
|
||
FNFError = FileNotFoundError | ||
_PathLike = str | bytes | PurePath | ||
else: | ||
FNFError = IOError | ||
_PathLike = Text | ||
|
||
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: | ||
val: Any | ||
comment: str | ||
def __init__(self, val: Any, comment: str, beginline: bool, _dict: type[MutableMapping[str, Any]]) -> None: ... | ||
def __getitem__(self, key: Any) -> Any: ... | ||
def __setitem__(self, key: Any, value: Any) -> None: ... | ||
def dump(self, dump_value_func: Callable[[Any], str]) -> str: ... | ||
|
||
@overload | ||
def load( | ||
f: _PathLike | list[Any] | SupportsRead[Text], # list[_PathLike] is invariance | ||
_dict: type[_MutableMappingT], | ||
decoder: TomlDecoder[_MutableMappingT] | None = ..., | ||
) -> _MutableMappingT: ... | ||
@overload | ||
def load( | ||
f: _PathLike | list[Any] | SupportsRead[Text], # list[_PathLike] is invariance | ||
_dict: type[dict[str, Any]] = ..., | ||
decoder: TomlDecoder[dict[str, Any]] | None = ..., | ||
) -> dict[str, Any]: ... | ||
@overload | ||
def loads(s: Text, _dict: type[_MutableMappingT], decoder: TomlDecoder[_MutableMappingT] | None = ...) -> _MutableMappingT: ... | ||
@overload | ||
def loads(s: Text, _dict: type[dict[str, Any]] = ..., decoder: TomlDecoder[dict[str, Any]] | None = ...) -> dict[str, Any]: ... | ||
|
||
class InlineTableDict: ... | ||
|
||
class TomlDecoder(Generic[_MutableMappingT]): | ||
_dict: type[_MutableMappingT] | ||
@overload | ||
def __init__(self, _dict: type[_MutableMappingT]) -> None: ... | ||
@overload | ||
def __init__(self: TomlDecoder[dict[str, Any]], _dict: type[dict[str, Any]] = ...) -> None: ... | ||
def get_empty_table(self) -> _MutableMappingT: ... | ||
def get_empty_inline_table(self) -> InlineTableDict: ... # incomplete python/typing#213 | ||
def load_inline_object( | ||
self, line: str, currentlevel: _MutableMappingT, multikey: bool = ..., multibackslash: bool = ... | ||
) -> None: ... | ||
def load_line( | ||
self, line: str, currentlevel: _MutableMappingT, multikey: bool | None, multibackslash: bool | ||
) -> tuple[bool | None, str, bool] | None: ... | ||
def load_value(self, v: str, strictly_valid: bool = ...) -> tuple[Any, str]: ... | ||
def bounded_string(self, s: str) -> bool: ... | ||
def load_array(self, a: str) -> list[Any]: ... | ||
def preserve_comment(self, line_no: int, key: str, comment: str, beginline: bool) -> None: ... | ||
def embed_comments(self, idx: int, currentlevel: _MutableMappingT) -> None: ... | ||
|
||
class TomlPreserveCommentDecoder(TomlDecoder[_MutableMappingT]): | ||
saved_comments: dict[int, tuple[str, str, bool]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from _typeshed import SupportsWrite | ||
from typing import Any, Callable, Generic, Iterable, Mapping, MutableMapping, TypeVar, overload | ||
|
||
_MappingT = TypeVar("_MappingT", bound=Mapping[str, Any]) | ||
|
||
def dump(o: _MappingT, f: SupportsWrite[str], encoder: TomlEncoder[_MappingT] | None = ...) -> str: ... | ||
def dumps(o: _MappingT, encoder: TomlEncoder[_MappingT] | None = ...) -> str: ... | ||
|
||
class TomlEncoder(Generic[_MappingT]): | ||
_dict: type[_MappingT] | ||
preserve: bool | ||
dump_funcs: MutableMapping[type[Any], Callable[[Any], str]] | ||
@overload | ||
def __init__(self, _dict: type[_MappingT], preserve: bool = ...) -> None: ... | ||
@overload | ||
def __init__(self: TomlEncoder[dict[str, Any]], _dict: type[dict[str, Any]] = ..., preserve: bool = ...) -> None: ... | ||
def get_empty_table(self) -> _MappingT: ... | ||
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: _MappingT, sup: str) -> tuple[str, _MappingT]: ... | ||
|
||
class TomlPreserveInlineDictEncoder(TomlEncoder[_MappingT]): | ||
@overload | ||
def __init__(self, _dict: type[_MappingT]) -> None: ... | ||
@overload | ||
def __init__(self: TomlPreserveInlineDictEncoder[dict[str, Any]], _dict: type[dict[str, Any]] = ...) -> None: ... | ||
|
||
class TomlArraySeparatorEncoder(TomlEncoder[_MappingT]): | ||
separator: str | ||
@overload | ||
def __init__(self, _dict: type[_MappingT], preserve: bool = ..., separator: str = ...) -> None: ... | ||
@overload | ||
def __init__( | ||
self: TomlArraySeparatorEncoder[dict[str, Any]], | ||
_dict: type[dict[str, Any]] = ..., | ||
preserve: bool = ..., | ||
separator: str = ..., | ||
) -> None: ... | ||
def dump_list(self, v: Iterable[Any]) -> str: ... | ||
|
||
class TomlNumpyEncoder(TomlEncoder[_MappingT]): ... | ||
class TomlPreserveCommentEncoder(TomlEncoder[_MappingT]): ... | ||
class TomlPathlibEncoder(TomlEncoder[_MappingT]): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from collections import OrderedDict | ||
from typing import Any | ||
|
||
from .decoder import TomlDecoder | ||
from .encoder import TomlEncoder | ||
|
||
class TomlOrderedDecoder(TomlDecoder[OrderedDict[str, Any]]): | ||
def __init__(self) -> None: ... | ||
|
||
class TomlOrderedEncoder(TomlEncoder[OrderedDict[str, Any]]): | ||
def __init__(self) -> None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from _typeshed import Self | ||
from datetime import datetime, timedelta, tzinfo | ||
from typing import Any | ||
|
||
class TomlTz(tzinfo): | ||
def __init__(self, toml_offset: str) -> None: ... | ||
def __deepcopy__(self: Self, memo: Any) -> Self: ... | ||
def tzname(self, dt: datetime | None) -> str: ... | ||
def utcoffset(self, dt: datetime | None) -> timedelta: ... | ||
def dst(self, dt: datetime | None) -> timedelta: ... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.