From 49e5b528dcef7bdc42990e2cce4602a62c47d5d5 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Fri, 12 Nov 2021 06:23:58 -0500 Subject: [PATCH] Add more type hints for pyyaml (#6265) --- stubs/PyYAML/yaml/__init__.pyi | 273 +++++++++++++++++---------------- stubs/PyYAML/yaml/dumper.pyi | 81 +++++----- 2 files changed, 183 insertions(+), 171 deletions(-) diff --git a/stubs/PyYAML/yaml/__init__.pyi b/stubs/PyYAML/yaml/__init__.pyi index cc246b6e7..3e202264e 100644 --- a/stubs/PyYAML/yaml/__init__.pyi +++ b/stubs/PyYAML/yaml/__init__.pyi @@ -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( diff --git a/stubs/PyYAML/yaml/dumper.pyi b/stubs/PyYAML/yaml/dumper.pyi index b2ca83fc8..6c89d3f95 100644 --- a/stubs/PyYAML/yaml/dumper.pyi +++ b/stubs/PyYAML/yaml/dumper.pyi @@ -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: ...