From 84682a1d545b789c7686aaf648c4066b40129506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Gr=C3=BCbel?= Date: Wed, 26 Oct 2022 09:15:35 +0200 Subject: [PATCH] Add a couple of missing type hints in pyyaml.constructor (#8965) --- stubs/PyYAML/yaml/constructor.pyi | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index 75da27e7a..a3187c33c 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,11 +1,12 @@ -from collections.abc import Callable +from collections.abc import Callable, Hashable +from datetime import date from re import Pattern -from typing import Any, TypeVar +from typing import Any, ClassVar, TypeVar from typing_extensions import TypeAlias from yaml.error import MarkedYAMLError from yaml.loader import BaseLoader, FullLoader, Loader, SafeLoader, UnsafeLoader -from yaml.nodes import Node, ScalarNode +from yaml.nodes import MappingNode, Node, ScalarNode, SequenceNode _L = TypeVar("_L", bound=Loader | BaseLoader | FullLoader | SafeLoader | UnsafeLoader) _N = TypeVar("_N", bound=Node) @@ -29,8 +30,8 @@ class BaseConstructor: def construct_document(self, node): ... def construct_object(self, node, deep=...): ... def construct_scalar(self, node: ScalarNode) -> _Scalar: ... - def construct_sequence(self, node, deep=...): ... - def construct_mapping(self, node, deep=...): ... + def construct_sequence(self, node: SequenceNode, deep: bool = ...) -> list[Any]: ... + def construct_mapping(self, node: MappingNode, deep: bool = ...) -> dict[Hashable, Any]: ... def construct_pairs(self, node, deep=...): ... @classmethod # Use typevars so we can have covariant behaviour in the parameter types @@ -40,18 +41,18 @@ class BaseConstructor: class SafeConstructor(BaseConstructor): def construct_scalar(self, node: ScalarNode) -> _Scalar: ... - def flatten_mapping(self, node): ... - def construct_mapping(self, node, deep=...): ... - def construct_yaml_null(self, node): ... - bool_values: Any - def construct_yaml_bool(self, node): ... - def construct_yaml_int(self, node): ... - inf_value: Any - nan_value: Any - def construct_yaml_float(self, node): ... - def construct_yaml_binary(self, node): ... - timestamp_regexp: Any - def construct_yaml_timestamp(self, node): ... + def flatten_mapping(self, node: MappingNode) -> None: ... + def construct_mapping(self, node: MappingNode, deep: bool = ...) -> dict[Hashable, Any]: ... + def construct_yaml_null(self, node: ScalarNode) -> None: ... + bool_values: ClassVar[dict[str, bool]] + def construct_yaml_bool(self, node: ScalarNode) -> bool: ... + def construct_yaml_int(self, node: ScalarNode) -> int: ... + inf_value: ClassVar[float] + nan_value: ClassVar[float] + def construct_yaml_float(self, node: ScalarNode) -> float: ... + def construct_yaml_binary(self, node: ScalarNode) -> bytes: ... + timestamp_regexp: ClassVar[Pattern[str]] + def construct_yaml_timestamp(self, node: ScalarNode) -> date: ... def construct_yaml_omap(self, node): ... def construct_yaml_pairs(self, node): ... def construct_yaml_set(self, node): ...