Upgrade PyYAML to version 6 (#6183)

* Fix load_all() argument
* Remove Python 2 remnants
  + Replace Text with str
  + Replace alias "_Str" with str
  + Import from collections.abc and re where applicable
  + Remove Python 2 branches
* Fix PyYaml allowlist entries
  + Add yaml._yaml and move CParser and CEmitter there.
  + Add missing functions, classes, and arguments.
* Use relative imports in some modules.
* Add __all__ to yaml.cyaml.
* Remove unnecessary noqa markers.
This commit is contained in:
Sebastian Rittau
2021-10-22 20:05:58 +02:00
committed by GitHub
parent 12dd8d9718
commit 4e592ada7b
7 changed files with 128 additions and 104 deletions

View File

@@ -1,8 +0,0 @@
yaml.CBaseDumper.__init__
yaml.CDumper.__init__
yaml.CEmitter
yaml.CParser
yaml.YAMLObjectMetaclass.__init__
yaml.constructor.FullConstructor.set_python_instance_state
yaml.cyaml.CBaseDumper.__init__
yaml.cyaml.CDumper.__init__

View File

@@ -1,2 +1 @@
version = "5.4.*"
python2 = true
version = "6.0.*"

View File

@@ -1,24 +1,19 @@
import sys
from typing import IO, Any, Callable, Iterable, Iterator, Pattern, Sequence, Text, Type, TypeVar, Union, overload
from yaml.constructor import BaseConstructor
from yaml.dumper import * # noqa: F403
from yaml.error import * # noqa: F403
from yaml.events import * # noqa: F403
from yaml.loader import * # noqa: F403
from yaml.nodes import * # noqa: F403
from yaml.representer import BaseRepresenter
from yaml.resolver import BaseResolver
from yaml.tokens import * # noqa: F403
from collections.abc import Callable, Iterable, Iterator, 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
from .constructor import BaseConstructor
from .cyaml import *
from .dumper import *
from .error import *
from .events import *
from .loader import *
from .nodes import *
from .representer import BaseRepresenter
from .resolver import BaseResolver
from .tokens import *
if sys.version_info >= (3, 0):
_Str = str
else:
_Str = Union[Text, str]
# FIXME: the functions really return py2:unicode/py3:str if encoding is None, otherwise py2:str/py3:bytes. Waiting for python/mypy#5621
# FIXME: the functions really return str if encoding is None, otherwise bytes. Waiting for python/mypy#5621
_Yaml = Any
__with_libyaml__: Any
@@ -28,18 +23,19 @@ _T = TypeVar("_T")
_Constructor = TypeVar("_Constructor", bound=BaseConstructor)
_Representer = TypeVar("_Representer", bound=BaseRepresenter)
def warnings(settings=...): ...
def scan(stream, Loader=...): ...
def parse(stream, Loader=...): ...
def compose(stream, Loader=...): ...
def compose_all(stream, Loader=...): ...
def load(stream: bytes | IO[bytes] | Text | IO[Text], Loader=...) -> Any: ...
def load_all(stream: bytes | IO[bytes] | Text | IO[Text], Loader=...) -> Iterator[Any]: ...
def full_load(stream: bytes | IO[bytes] | Text | IO[Text]) -> Any: ...
def full_load_all(stream: bytes | IO[bytes] | Text | IO[Text]) -> Iterator[Any]: ...
def safe_load(stream: bytes | IO[bytes] | Text | IO[Text]) -> Any: ...
def safe_load_all(stream: bytes | IO[bytes] | Text | IO[Text]) -> Iterator[Any]: ...
def unsafe_load(stream: bytes | IO[bytes] | Text | IO[Text]) -> Any: ...
def unsafe_load_all(stream: bytes | IO[bytes] | Text | IO[Text]) -> Iterator[Any]: ...
def load(stream: bytes | IO[bytes] | str | IO[str], Loader) -> Any: ...
def load_all(stream: bytes | IO[bytes] | str | IO[str], Loader) -> Iterator[Any]: ...
def full_load(stream: bytes | IO[bytes] | str | IO[str]) -> Any: ...
def full_load_all(stream: bytes | IO[bytes] | str | IO[str]) -> Iterator[Any]: ...
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=...): ...
@overload
def serialize_all(
@@ -67,7 +63,7 @@ def serialize_all(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -101,7 +97,7 @@ def serialize(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -138,7 +134,7 @@ def dump_all(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -178,7 +174,7 @@ def dump(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -216,7 +212,7 @@ def safe_dump_all(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -254,7 +250,7 @@ def safe_dump(
width=...,
allow_unicode=...,
line_break=...,
encoding: _Str | None = ...,
encoding: str | None = ...,
explicit_start=...,
explicit_end=...,
version=...,
@@ -262,14 +258,14 @@ def safe_dump(
sort_keys: bool = ...,
) -> _Yaml: ...
def add_implicit_resolver(
tag: _Str,
tag: str,
regexp: Pattern[str],
first: Iterable[Any] | None = ...,
Loader: Type[BaseResolver] | None = ...,
Dumper: Type[BaseResolver] = ...,
) -> None: ...
def add_path_resolver(
tag: _Str,
tag: str,
path: Iterable[Any],
kind: Type[Any] | None = ...,
Loader: Type[BaseResolver] | None = ...,
@@ -277,17 +273,17 @@ def add_path_resolver(
) -> None: ...
@overload
def add_constructor(
tag: _Str, constructor: Callable[[Loader | FullLoader | UnsafeLoader, Node], Any], Loader: None = ...
tag: str, constructor: Callable[[Loader | FullLoader | UnsafeLoader, Node], Any], Loader: None = ...
) -> None: ...
@overload
def add_constructor(tag: _Str, constructor: Callable[[_Constructor, Node], Any], Loader: Type[_Constructor]) -> None: ...
def add_constructor(tag: str, constructor: Callable[[_Constructor, Node], Any], Loader: Type[_Constructor]) -> None: ...
@overload
def add_multi_constructor(
tag_prefix: _Str, multi_constructor: Callable[[Loader | FullLoader | UnsafeLoader, _Str, Node], Any], Loader: None = ...
tag_prefix: str, multi_constructor: Callable[[Loader | FullLoader | UnsafeLoader, str, Node], Any], Loader: None = ...
) -> None: ...
@overload
def add_multi_constructor(
tag_prefix: _Str, multi_constructor: Callable[[_Constructor, _Str, Node], Any], Loader: Type[_Constructor]
tag_prefix: str, multi_constructor: Callable[[_Constructor, str, Node], Any], Loader: Type[_Constructor]
) -> None: ...
@overload
def add_representer(data_type: Type[_T], representer: Callable[[Dumper, _T], Node]) -> None: ...
@@ -301,7 +297,7 @@ def add_multi_representer(
) -> None: ...
class YAMLObjectMetaclass(type):
def __init__(self, name, bases, kwds) -> None: ...
def __init__(cls, name, bases, kwds) -> None: ...
class YAMLObject(metaclass=YAMLObjectMetaclass):
yaml_loader: Any

View File

@@ -0,0 +1,56 @@
from _typeshed import SupportsRead
from collections.abc import Mapping, Sequence
from typing import IO, Any
from .events import Event
from .nodes import Node
from .tokens import Token
def get_version_string() -> str: ...
def get_version() -> tuple[int, int, int]: ...
class Mark:
name: Any
index: int
line: int
column: int
buffer: Any
pointer: Any
def __init__(self, name, index: int, line: int, column: int, buffer, pointer) -> None: ...
def get_snippet(self): ...
class CParser:
def __init__(self, stream: str | bytes | SupportsRead[str | bytes]) -> None: ...
def dispose(self) -> None: ...
def get_token(self) -> Token | None: ...
def peek_token(self) -> Token | None: ...
def check_token(self, *choices) -> bool: ...
def get_event(self) -> Event | None: ...
def peek_event(self) -> Event | None: ...
def check_event(self, *choices) -> bool: ...
def check_node(self) -> bool: ...
def get_node(self) -> Node | None: ...
def get_single_node(self) -> Node | None: ...
def raw_parse(self) -> int: ...
def raw_scan(self) -> int: ...
class CEmitter:
def __init__(
self,
stream: IO[Any],
canonical: Any | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: Any | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: Any | None = ...,
explicit_end: Any | None = ...,
version: Sequence[int] | None = ...,
tags: Mapping[str, str] | None = ...,
) -> None: ...
def dispose(self) -> None: ...
def emit(self, event_object) -> None: ...
def open(self) -> None: ...
def close(self) -> None: ...
def serialize(self, node) -> None: ...

View File

@@ -1,10 +1,9 @@
import sys
from typing import Any, Text, Union
from typing import Any, Pattern, Union
from yaml.error import MarkedYAMLError
from yaml.nodes import ScalarNode
_Scalar = Union[Text, int, float, bool, None]
_Scalar = Union[str, int, float, bool, None]
class ConstructorError(MarkedYAMLError): ...
@@ -17,6 +16,7 @@ class BaseConstructor:
deep_construct: Any
def __init__(self) -> None: ...
def check_data(self): ...
def check_state_key(self, key: str) -> None: ...
def get_data(self): ...
def get_single_data(self) -> Any: ...
def construct_document(self, node): ...
@@ -54,6 +54,8 @@ class SafeConstructor(BaseConstructor):
def construct_undefined(self, node): ...
class FullConstructor(SafeConstructor):
def get_state_keys_blacklist(self) -> list[str]: ...
def get_state_keys_blacklist_regexp(self) -> Pattern[str]: ...
def construct_python_str(self, node): ...
def construct_python_unicode(self, node): ...
def construct_python_bytes(self, node): ...
@@ -65,7 +67,7 @@ class FullConstructor(SafeConstructor):
def construct_python_name(self, suffix, node): ...
def construct_python_module(self, suffix, node): ...
def make_python_instance(self, suffix, node, args=..., kwds=..., newobj=..., unsafe=...): ...
def set_python_instance_state(self, instance, state): ...
def set_python_instance_state(self, instance, state, unsafe: bool = ...) -> None: ...
def construct_python_object(self, suffix, node): ...
def construct_python_object_apply(self, suffix, node, newobj=...): ...
def construct_python_object_new(self, suffix, node): ...
@@ -86,8 +88,6 @@ class Constructor(SafeConstructor):
def find_python_name(self, name, mark): ...
def construct_python_name(self, suffix, node): ...
def construct_python_module(self, suffix, node): ...
if sys.version_info < (3, 0):
class classobj: ...
def make_python_instance(self, suffix, node, args=..., kwds=..., newobj=...): ...
def set_python_instance_state(self, instance, state): ...
def construct_python_object(self, suffix, node): ...

View File

@@ -1,27 +1,15 @@
from _typeshed import SupportsRead
from typing import IO, Any, Mapping, Sequence, Text, Union
from collections.abc import Mapping, Sequence
from typing import IO, Any, Union
from yaml.constructor import BaseConstructor, FullConstructor, SafeConstructor, UnsafeConstructor
from yaml.events import Event
from yaml.nodes import Node
from yaml.representer import BaseRepresenter, SafeRepresenter
from yaml.resolver import BaseResolver, Resolver
from yaml.tokens import Token
from ._yaml import CEmitter, CParser
from .constructor import BaseConstructor, FullConstructor, SafeConstructor, UnsafeConstructor
from .representer import BaseRepresenter, SafeRepresenter
from .resolver import BaseResolver, Resolver
_Readable = SupportsRead[Union[Text, bytes]]
__all__ = ["CBaseLoader", "CSafeLoader", "CFullLoader", "CUnsafeLoader", "CLoader", "CBaseDumper", "CSafeDumper", "CDumper"]
class CParser:
def __init__(self, stream: str | bytes | _Readable) -> None: ...
def dispose(self) -> None: ...
def get_token(self) -> Token | None: ...
def peek_token(self) -> Token | None: ...
def check_token(self, *choices) -> bool: ...
def get_event(self) -> Event | None: ...
def peek_event(self) -> Event | None: ...
def check_event(self, *choices) -> bool: ...
def check_node(self) -> bool: ...
def get_node(self) -> Node | None: ...
def get_single_node(self) -> Node | None: ...
_Readable = SupportsRead[Union[str, bytes]]
class CBaseLoader(CParser, BaseConstructor, BaseResolver):
def __init__(self, stream: str | bytes | _Readable) -> None: ...
@@ -38,22 +26,6 @@ class CFullLoader(CParser, FullConstructor, Resolver):
class CUnsafeLoader(CParser, UnsafeConstructor, Resolver):
def __init__(self, stream: str | bytes | _Readable) -> None: ...
class CEmitter(object):
def __init__(
self,
stream: IO[Any],
canonical: Any | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: Any | None = ...,
line_break: str | None = ...,
encoding: Text | None = ...,
explicit_start: Any | None = ...,
explicit_end: Any | None = ...,
version: Sequence[int] | None = ...,
tags: Mapping[Text, Text] | None = ...,
) -> None: ...
class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver):
def __init__(
self,
@@ -65,13 +37,31 @@ class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver):
width: int | None = ...,
allow_unicode: Any | None = ...,
line_break: str | None = ...,
encoding: Text | None = ...,
encoding: str | None = ...,
explicit_start: Any | None = ...,
explicit_end: Any | None = ...,
version: Sequence[int] | None = ...,
tags: Mapping[Text, Text] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
class CDumper(CEmitter, SafeRepresenter, Resolver): ...
class CDumper(CEmitter, SafeRepresenter, Resolver):
def __init__(
self,
stream: IO[Any],
default_style: str | None = ...,
default_flow_style: bool = ...,
canonical: Any | None = ...,
indent: int | None = ...,
width: int | None = ...,
allow_unicode: Any | None = ...,
line_break: str | None = ...,
encoding: str | None = ...,
explicit_start: Any | None = ...,
explicit_end: Any | None = ...,
version: Sequence[int] | None = ...,
tags: Mapping[str, str] | None = ...,
sort_keys: bool = ...,
) -> None: ...
CSafeDumper = CDumper

View File

@@ -1,8 +1,8 @@
import datetime
import sys
from _typeshed import SupportsItems
from collections.abc import Callable, Iterable, Mapping
from types import BuiltinFunctionType, FunctionType, ModuleType
from typing import Any, Callable, ClassVar, Iterable, Mapping, NoReturn, Type, TypeVar
from typing import Any, ClassVar, NoReturn, Type, TypeVar
from yaml.error import YAMLError as YAMLError
from yaml.nodes import MappingNode as MappingNode, Node as Node, ScalarNode as ScalarNode, SequenceNode as SequenceNode
@@ -24,8 +24,6 @@ class BaseRepresenter:
def __init__(self, default_style: str | None = ..., default_flow_style: bool = ..., sort_keys: bool = ...) -> None: ...
def represent(self, data) -> None: ...
def represent_data(self, data) -> Node: ...
if sys.version_info < (3, 0):
def get_classobj_bases(self, cls): ...
@classmethod
def add_representer(cls: Type[_R], data_type: Type[_T], representer: Callable[[_R, _T], Node]) -> None: ...
@classmethod
@@ -42,9 +40,6 @@ class SafeRepresenter(BaseRepresenter):
def ignore_aliases(self, data) -> bool: ...
def represent_none(self, data) -> ScalarNode: ...
def represent_str(self, data: str) -> ScalarNode: ...
if sys.version_info < (3, 0):
def represent_unicode(self, data): ...
def represent_long(self, data): ...
def represent_binary(self, data: bytes) -> ScalarNode: ...
def represent_bool(self, data: bool) -> ScalarNode: ...
def represent_int(self, data: int) -> ScalarNode: ...
@@ -58,10 +53,6 @@ class SafeRepresenter(BaseRepresenter):
def represent_undefined(self, data) -> NoReturn: ...
class Representer(SafeRepresenter):
if sys.version_info < (3, 0):
def represent_unicode(self, data): ...
def represent_long(self, data): ...
def represent_instance(self, data): ...
def represent_complex(self, data: complex) -> ScalarNode: ...
def represent_tuple(self, data: Iterable[Any]) -> SequenceNode: ...
def represent_name(self, data: BuiltinFunctionType | FunctionType) -> ScalarNode: ...