mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
loosen type restrictions for mapping representer input (#5640)
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
import sys
|
||||
from types import BuiltinFunctionType, FunctionType, ModuleType
|
||||
from typing import Any, Callable, ClassVar, Mapping, NoReturn, Sequence, Tuple, Type, TypeVar
|
||||
from typing import Any, Callable, ClassVar, Iterable, Mapping, NoReturn, Tuple, Type, TypeVar, Union
|
||||
|
||||
from yaml.error import YAMLError as YAMLError
|
||||
from yaml.nodes import MappingNode as MappingNode, Node as Node, ScalarNode as ScalarNode, SequenceNode as SequenceNode
|
||||
@@ -9,6 +9,8 @@ from yaml.nodes import MappingNode as MappingNode, Node as Node, ScalarNode as S
|
||||
_T = TypeVar("_T")
|
||||
_R = TypeVar("_R", bound=BaseRepresenter)
|
||||
|
||||
MappingLike = Union[Mapping[Any, Any], Iterable[Tuple[Any, Any]]]
|
||||
|
||||
class RepresenterError(YAMLError): ...
|
||||
|
||||
class BaseRepresenter:
|
||||
@@ -30,8 +32,8 @@ class BaseRepresenter:
|
||||
@classmethod
|
||||
def add_multi_representer(cls: Type[_R], data_type: Type[_T], representer: Callable[[_R, _T], Node]) -> None: ...
|
||||
def represent_scalar(self, tag: str, value, style: str | None = ...) -> ScalarNode: ...
|
||||
def represent_sequence(self, tag: str, sequence: Sequence[Any], flow_style: bool | None = ...) -> SequenceNode: ...
|
||||
def represent_mapping(self, tag: str, mapping: Mapping[Any, Any], flow_style: bool | None = ...) -> MappingNode: ...
|
||||
def represent_sequence(self, tag: str, sequence: Iterable[Any], flow_style: bool | None = ...) -> SequenceNode: ...
|
||||
def represent_mapping(self, tag: str, mapping: MappingLike, flow_style: bool | None = ...) -> MappingNode: ...
|
||||
def ignore_aliases(self, data) -> bool: ...
|
||||
|
||||
class SafeRepresenter(BaseRepresenter):
|
||||
@@ -46,9 +48,9 @@ class SafeRepresenter(BaseRepresenter):
|
||||
def represent_bool(self, data: bool) -> ScalarNode: ...
|
||||
def represent_int(self, data: int) -> ScalarNode: ...
|
||||
def represent_float(self, data: float) -> ScalarNode: ...
|
||||
def represent_list(self, data: Sequence[Any]) -> SequenceNode: ...
|
||||
def represent_dict(self, data: Mapping[Any, Any]) -> MappingNode: ...
|
||||
def represent_set(self, data: set[Any]) -> MappingNode: ...
|
||||
def represent_list(self, data: Iterable[Any]) -> SequenceNode: ...
|
||||
def represent_dict(self, data: MappingLike) -> MappingNode: ...
|
||||
def represent_set(self, data: Iterable[Any]) -> MappingNode: ...
|
||||
def represent_date(self, data: datetime.date) -> ScalarNode: ...
|
||||
def represent_datetime(self, data: datetime.datetime) -> ScalarNode: ...
|
||||
def represent_yaml_object(self, tag: str, data, cls, flow_style: bool | None = ...) -> MappingNode: ...
|
||||
@@ -60,7 +62,7 @@ class Representer(SafeRepresenter):
|
||||
def represent_long(self, data): ...
|
||||
def represent_instance(self, data): ...
|
||||
def represent_complex(self, data: complex) -> ScalarNode: ...
|
||||
def represent_tuple(self, data: Tuple[Any, ...]) -> SequenceNode: ...
|
||||
def represent_tuple(self, data: Iterable[Any]) -> SequenceNode: ...
|
||||
def represent_name(self, data: BuiltinFunctionType | FunctionType) -> ScalarNode: ...
|
||||
def represent_module(self, data: ModuleType) -> ScalarNode: ...
|
||||
def represent_object(self, data) -> SequenceNode | MappingNode: ...
|
||||
|
||||
Reference in New Issue
Block a user