Skip to content

Commit 77c5c8d

Browse files
committed
yaml.dump(): Drop distinguishing encoding
As far as I know it's currently impossible to use "overloads with return types depending on optional arguments" (Issue #5621). As "encoding" is in the middle of 11 optional arguments, it would require ~ 2^6 overloads for each of those 6 functions. For now just return Any and wait for Issue #5621 to get fixed.
1 parent 415cca0 commit 77c5c8d

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

third_party/2and3/yaml/__init__.pyi

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, AnyStr, Iterator, overload, Sequence, Union, IO
1+
from typing import Any, Iterator, overload, Sequence, Union, IO
22
from yaml.error import * # noqa: F403
33
from yaml.tokens import * # noqa: F403
44
from yaml.events import * # noqa: F403
@@ -8,6 +8,14 @@ from yaml.dumper import * # noqa: F403
88
from . import resolver # Help mypy a bit; this is implied by loader and dumper
99
# TODO: stubs for cyaml?
1010
# from cyaml import *
11+
import sys
12+
13+
if sys.version_info < (3,):
14+
_Str = Union[Text, str]
15+
else:
16+
_Str = str
17+
# FIXME: the functions really return py2:unicode/py3:str if encoding is None, otherwise py2:str/py3:bytes. Waiting for Issue#5621
18+
_Yaml = Any
1119

1220
__with_libyaml__ = ... # type: Any
1321

@@ -21,47 +29,35 @@ def safe_load(stream: Union[str, IO[str]]) -> Any: ...
2129
def safe_load_all(stream: Union[str, IO[str]]) -> Iterator[Any]: ...
2230
def emit(events, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=...): ...
2331

24-
@overload
25-
def serialize_all(nodes, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
26-
@overload
27-
def serialize_all(nodes, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
2832
@overload
2933
def serialize_all(nodes, stream: IO[str], Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
30-
31-
@overload
32-
def serialize(node, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
3334
@overload
34-
def serialize(node, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
35-
@overload
36-
def serialize(node, stream: IO[str], Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
35+
def serialize_all(nodes, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
3736

3837
@overload
39-
def dump_all(documents: Sequence[Any], stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
40-
@overload
41-
def dump_all(documents: Sequence[Any], stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
38+
def serialize(node, stream: IO[str], Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
4239
@overload
43-
def dump_all(documents: Sequence[Any], stream: IO[str], Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
40+
def serialize(node, stream: None=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
4441

4542
@overload
46-
def dump(data: Any, stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
47-
@overload
48-
def dump(data: Any, stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
43+
def dump_all(documents: Sequence[Any], stream: IO[str], Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
4944
@overload
50-
def dump(data: Any, stream: IO[str], Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
45+
def dump_all(documents: Sequence[Any], stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
5146

5247
@overload
53-
def save_dump_all(documents: Sequence[Any], stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
54-
@overload
55-
def save_dump_all(documents: Sequence[Any], stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
48+
def dump(data: Any, stream: IO[str], Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
5649
@overload
57-
def save_dump_all(documents: Sequence[Any], stream: IO[str], default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
50+
def dump(data: Any, stream: None=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
5851

5952
@overload
60-
def save_dump(data: Any, stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: None=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> str: ...
53+
def save_dump_all(documents: Sequence[Any], stream: IO[str], default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
6154
@overload
62-
def save_dump(data: Any, stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: str=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> bytes: ...
55+
def save_dump_all(documents: Sequence[Any], stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
56+
6357
@overload
6458
def save_dump(data: Any, stream: IO[str], default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ...
59+
@overload
60+
def save_dump(data: Any, stream: None=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding: Optional[_Str]=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> _Yaml: ...
6561

6662
def add_implicit_resolver(tag, regexp, first=..., Loader=..., Dumper=...): ...
6763
def add_path_resolver(tag, path, kind=..., Loader=..., Dumper=...): ...

0 commit comments

Comments
 (0)