Add more type hints for pyyaml (#6265)

This commit is contained in:
Steve Dignam
2021-11-12 06:23:58 -05:00
committed by GitHub
parent 9c9853967d
commit 49e5b528dc
2 changed files with 183 additions and 171 deletions

View File

@@ -1,4 +1,4 @@
from collections.abc import Callable, Iterable, Iterator, Sequence
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import IO, Any, Pattern, Type, TypeVar, overload
from . import resolver as resolver # Help mypy a bit; this is implied by loader and dumper
@@ -36,38 +36,47 @@ def safe_load(stream: bytes | IO[bytes] | str | IO[str]) -> Any: ...
def safe_load_all(stream: bytes | IO[bytes] | str | IO[str]) -> Iterator[Any]: ...
def unsafe_load(stream: bytes | IO[bytes] | str | IO[str]) -> Any: ...
def unsafe_load_all(stream: bytes | IO[bytes] | str | IO[str]) -> Iterator[Any]: ...
def emit(events, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=...): ...
def emit(
events,
stream=...,
Dumper=...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
): ...
@overload
def serialize_all(
nodes,
stream: IO[str],
Dumper=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
) -> None: ...
@overload
def serialize_all(
nodes,
stream: None = ...,
Dumper=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
) -> _Yaml: ...
@overload
def serialize(
@@ -75,16 +84,16 @@ def serialize(
stream: IO[str],
Dumper=...,
*,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
) -> None: ...
@overload
def serialize(
@@ -92,34 +101,34 @@ def serialize(
stream: None = ...,
Dumper=...,
*,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
) -> _Yaml: ...
@overload
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=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
@overload
@@ -127,18 +136,18 @@ def dump_all(
documents: Sequence[Any],
stream: None = ...,
Dumper=...,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> _Yaml: ...
@overload
@@ -147,18 +156,18 @@ def dump(
stream: IO[str],
Dumper=...,
*,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
@overload
@@ -167,18 +176,18 @@ def dump(
stream: None = ...,
Dumper=...,
*,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> _Yaml: ...
@overload
@@ -186,18 +195,18 @@ def safe_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=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
@overload
@@ -205,18 +214,18 @@ def safe_dump_all(
documents: Sequence[Any],
stream: None = ...,
*,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> _Yaml: ...
@overload
@@ -224,18 +233,18 @@ def safe_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=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
@overload
@@ -243,18 +252,18 @@ def safe_dump(
data: Any,
stream: None = ...,
*,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> _Yaml: ...
def add_implicit_resolver(

View File

@@ -1,3 +1,6 @@
from _typeshed import SupportsWrite
from collections.abc import Mapping
from yaml.emitter import Emitter
from yaml.representer import BaseRepresenter, Representer, SafeRepresenter
from yaml.resolver import BaseResolver, Resolver
@@ -6,56 +9,56 @@ from yaml.serializer import Serializer
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
def __init__(
self,
stream,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
stream: SupportsWrite[bytes | str],
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
def __init__(
self,
stream,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
stream: SupportsWrite[bytes | str],
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
class Dumper(Emitter, Serializer, Representer, Resolver):
def __init__(
self,
stream,
default_style=...,
default_flow_style=...,
canonical=...,
indent=...,
width=...,
allow_unicode=...,
line_break=...,
encoding=...,
explicit_start=...,
explicit_end=...,
version=...,
tags=...,
stream: SupportsWrite[bytes | str],
default_style: str | None = ...,
default_flow_style: bool | None = ...,
canonical: bool | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: bool | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: bool | None = ...,
explicit_end: bool | None = ...,
version: tuple[int, int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...