From 3a3a2796fbbc058fe8bf8d9e4969416b49656c81 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 1 Aug 2018 20:55:48 -0700 Subject: [PATCH 1/4] Add stub for toml See https://github.com/uiri/toml/issues/178 --- third_party/2and3/toml.pyi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 third_party/2and3/toml.pyi diff --git a/third_party/2and3/toml.pyi b/third_party/2and3/toml.pyi new file mode 100644 index 000000000000..acdaa13ebfb5 --- /dev/null +++ b/third_party/2and3/toml.pyi @@ -0,0 +1,14 @@ +from typing import Any, IO, Mapping, MutableMapping, Optional, Type, Union +import datetime + + +class TomlDecodeError(Exception): ... + +class TomlTz(datetime.tzinfo): + def __init__(self, toml_offset: str) -> None: ... + +def load(f: Union[str, list, IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... +def loads(s: str, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... + +def dump(o: Mapping[str, Any], f: IO[str]) -> str: ... +def dumps(o: Mapping[str, Any]) -> str: ... From 127f0406615c3402d232b25d35087c55a1117116 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 2 Aug 2018 20:14:11 -0700 Subject: [PATCH 2/4] Respond to code review I decided to add PathLike and pathlib.PurePath support since those look pretty intentional (https://github.com/uiri/toml/issues/159). --- third_party/2and3/toml.pyi | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/third_party/2and3/toml.pyi b/third_party/2and3/toml.pyi index acdaa13ebfb5..a05652291048 100644 --- a/third_party/2and3/toml.pyi +++ b/third_party/2and3/toml.pyi @@ -1,14 +1,27 @@ -from typing import Any, IO, Mapping, MutableMapping, Optional, Type, Union +from typing import Any, IO, Mapping, MutableMapping, Optional, Protocol, Text, Type, Union import datetime +import sys +if sys.version_info >= (3, 4): + import pathlib + if sys.version_info >= (3, 6): + import os + _PathLike = Union[Text, pathlib.PurePath, os.PathLike] + else: + _PathLike = Union[Text, pathlib.PurePath] +else: + _PathLike = Text + +class _Writable(Protocol): + def write(self, obj: str) -> Any: ... class TomlDecodeError(Exception): ... class TomlTz(datetime.tzinfo): def __init__(self, toml_offset: str) -> None: ... -def load(f: Union[str, list, IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... -def loads(s: str, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... +def load(f: Union[_PathLike, List[Text], IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... +def loads(s: Text, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... -def dump(o: Mapping[str, Any], f: IO[str]) -> str: ... +def dump(o: Mapping[str, Any], f: _Writable) -> str: ... def dumps(o: Mapping[str, Any]) -> str: ... From cb53e8dbf2ec117984601c0b80b3ad22986cd50b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 2 Aug 2018 21:37:13 -0700 Subject: [PATCH 3/4] Delete TomlTz -- it doesn't exist at the top-level. --- third_party/2and3/toml.pyi | 3 --- 1 file changed, 3 deletions(-) diff --git a/third_party/2and3/toml.pyi b/third_party/2and3/toml.pyi index a05652291048..fa4422807fb5 100644 --- a/third_party/2and3/toml.pyi +++ b/third_party/2and3/toml.pyi @@ -17,9 +17,6 @@ class _Writable(Protocol): class TomlDecodeError(Exception): ... -class TomlTz(datetime.tzinfo): - def __init__(self, toml_offset: str) -> None: ... - def load(f: Union[_PathLike, List[Text], IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... def loads(s: Text, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ... From a7e0363c980aac34b259dc85b25b0905ab0546c8 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 2 Aug 2018 21:39:44 -0700 Subject: [PATCH 4/4] Import List to fix tests --- third_party/2and3/toml.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/toml.pyi b/third_party/2and3/toml.pyi index fa4422807fb5..2639178e03dd 100644 --- a/third_party/2and3/toml.pyi +++ b/third_party/2and3/toml.pyi @@ -1,4 +1,4 @@ -from typing import Any, IO, Mapping, MutableMapping, Optional, Protocol, Text, Type, Union +from typing import Any, IO, List, Mapping, MutableMapping, Optional, Protocol, Text, Type, Union import datetime import sys