diff --git a/src/msgspec/__init__.pyi b/src/msgspec/__init__.pyi index 4d12b45b..7fb8d844 100644 --- a/src/msgspec/__init__.pyi +++ b/src/msgspec/__init__.pyi @@ -1,19 +1,12 @@ import enum +from collections.abc import Callable, Iterable, Mapping from inspect import Signature from typing import ( Any, - Callable, ClassVar, - Dict, Final, - Iterable, Literal, - Mapping, - Optional, - Tuple, - Type, TypeVar, - Union, overload, ) @@ -29,29 +22,27 @@ from . import inspect, json, msgpack, structs, toml, yaml _SM = TypeVar("_SM", bound="StructMeta") class StructMeta(type): - __struct_fields__: ClassVar[Tuple[str, ...]] - __struct_defaults__: ClassVar[Tuple[Any, ...]] - __struct_encode_fields__: ClassVar[Tuple[str, ...]] - __match_args__: ClassVar[Tuple[str, ...]] + __struct_fields__: ClassVar[tuple[str, ...]] + __struct_defaults__: ClassVar[tuple[Any, ...]] + __struct_encode_fields__: ClassVar[tuple[str, ...]] + __match_args__: ClassVar[tuple[str, ...]] @property def __signature__(self) -> Signature: ... @property def __struct_config__(self) -> structs.StructConfig: ... def __new__( - mcls: Type[_SM], + mcls: type[_SM], name: str, - bases: Tuple[type, ...], - namespace: Dict[str, Any], + bases: tuple[type, ...], + namespace: dict[str, Any], /, *, - tag: Union[None, bool, str, int, Callable[[str], Union[str, int]]] = None, - tag_field: Union[None, str] = None, - rename: Union[ - None, - Literal["lower", "upper", "camel", "pascal", "kebab"], - Callable[[str], Optional[str]], - Mapping[str, str], - ] = None, + tag: None | bool | str | int | Callable[[str], str | int] = None, + tag_field: None | str = None, + rename: None + | Literal["lower", "upper", "camel", "pascal", "kebab"] + | Callable[[str], str | None] + | Mapping[str, str] = None, omit_defaults: bool = False, forbid_unknown_fields: bool = False, frozen: bool = False, @@ -79,29 +70,27 @@ class _NoDefault(enum.Enum): NODEFAULT = _NoDefault.NODEFAULT @overload -def field(*, default: T, name: Optional[str] = None) -> T: ... +def field(*, default: T, name: str | None = None) -> T: ... @overload -def field(*, default_factory: Callable[[], T], name: Optional[str] = None) -> T: ... +def field(*, default_factory: Callable[[], T], name: str | None = None) -> T: ... @overload -def field(*, name: Optional[str] = None) -> Any: ... +def field(*, name: str | None = None) -> Any: ... @dataclass_transform(field_specifiers=(field,)) class Struct(metaclass=StructMeta): - __struct_fields__: ClassVar[Tuple[str, ...]] + __struct_fields__: ClassVar[tuple[str, ...]] __struct_config__: ClassVar[structs.StructConfig] - __match_args__: ClassVar[Tuple[str, ...]] + __match_args__: ClassVar[tuple[str, ...]] # A default __init__ so that Structs with unknown field types (say # constructed by `defstruct`) won't error on every call to `__init__` def __init__(self, *args: Any, **kwargs: Any) -> None: ... def __init_subclass__( cls, - tag: Union[None, bool, str, int, Callable[[str], Union[str, int]]] = None, - tag_field: Union[None, str] = None, - rename: Union[ - None, - Literal["lower", "upper", "camel", "pascal", "kebab"], - Callable[[str], Optional[str]], - Mapping[str, str], - ] = None, + tag: None | bool | str | int | Callable[[str], str | int] = None, + tag_field: None | str = None, + rename: None + | Literal["lower", "upper", "camel", "pascal", "kebab"] + | Callable[[str], str | None] + | Mapping[str, str] = None, omit_defaults: bool = False, forbid_unknown_fields: bool = False, frozen: bool = False, @@ -117,23 +106,21 @@ class Struct(metaclass=StructMeta): ) -> None: ... def __rich_repr__( self, - ) -> Iterable[Union[Any, Tuple[Any], Tuple[str, Any], Tuple[str, Any, Any]]]: ... + ) -> Iterable[Any | tuple[Any] | tuple[str, Any] | tuple[str, Any, Any]]: ... def defstruct( name: str, - fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Any]]], + fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], *, - bases: Optional[Tuple[Type[Struct], ...]] = None, - module: Optional[str] = None, - namespace: Optional[Dict[str, Any]] = None, - tag: Union[None, bool, str, int, Callable[[str], Union[str, int]]] = None, - tag_field: Union[None, str] = None, - rename: Union[ - None, - Literal["lower", "upper", "camel", "pascal", "kebab"], - Callable[[str], Optional[str]], - Mapping[str, str], - ] = None, + bases: tuple[type[Struct], ...] | None = None, + module: str | None = None, + namespace: dict[str, Any] | None = None, + tag: None | bool | str | int | Callable[[str], str | int] = None, + tag_field: None | str = None, + rename: None + | Literal["lower", "upper", "camel", "pascal", "kebab"] + | Callable[[str], str | None] + | Mapping[str, str] = None, omit_defaults: bool = False, forbid_unknown_fields: bool = False, frozen: bool = False, @@ -146,69 +133,69 @@ def defstruct( weakref: bool = False, dict: bool = False, cache_hash: bool = False, -) -> Type[Struct]: ... +) -> type[Struct]: ... # Lie and say `Raw` is a subclass of `bytes`, so mypy will accept it in most # places where an object that implements the buffer protocol is valid class Raw(bytes): @overload - def __new__(cls) -> "Raw": ... + def __new__(cls) -> Raw: ... @overload - def __new__(cls, msg: Union[Buffer, str]) -> "Raw": ... - def copy(self) -> "Raw": ... + def __new__(cls, msg: Buffer | str) -> Raw: ... + def copy(self) -> Raw: ... class Meta: def __init__( self, *, - gt: Union[int, float, None] = None, - ge: Union[int, float, None] = None, - lt: Union[int, float, None] = None, - le: Union[int, float, None] = None, - multiple_of: Union[int, float, None] = None, - pattern: Union[str, None] = None, - min_length: Union[int, None] = None, - max_length: Union[int, None] = None, - tz: Union[bool, None] = None, - title: Union[str, None] = None, - description: Union[str, None] = None, - examples: Union[list, None] = None, - extra_json_schema: Union[dict, None] = None, - extra: Union[dict, None] = None, + gt: int | float | None = None, + ge: int | float | None = None, + lt: int | float | None = None, + le: int | float | None = None, + multiple_of: int | float | None = None, + pattern: str | None = None, + min_length: int | None = None, + max_length: int | None = None, + tz: bool | None = None, + title: str | None = None, + description: str | None = None, + examples: list | None = None, + extra_json_schema: dict | None = None, + extra: dict | None = None, ): ... - gt: Final[Union[int, float, None]] - ge: Final[Union[int, float, None]] - lt: Final[Union[int, float, None]] - le: Final[Union[int, float, None]] - multiple_of: Final[Union[int, float, None]] - pattern: Final[Union[str, None]] - min_length: Final[Union[int, None]] - max_length: Final[Union[int, None]] - tz: Final[Union[int, None]] - title: Final[Union[str, None]] - description: Final[Union[str, None]] - examples: Final[Union[list, None]] - extra_json_schema: Final[Union[dict, None]] - extra: Final[Union[dict, None]] - def __rich_repr__(self) -> Iterable[Tuple[str, Any]]: ... + gt: Final[int | float | None] + ge: Final[int | float | None] + lt: Final[int | float | None] + le: Final[int | float | None] + multiple_of: Final[int | float | None] + pattern: Final[str | None] + min_length: Final[int | None] + max_length: Final[int | None] + tz: Final[int | None] + title: Final[str | None] + description: Final[str | None] + examples: Final[list | None] + extra_json_schema: Final[dict | None] + extra: Final[dict | None] + def __rich_repr__(self) -> Iterable[tuple[str, Any]]: ... def to_builtins( obj: Any, *, str_keys: bool = False, - builtin_types: Union[Iterable[type], None] = None, - enc_hook: Optional[Callable[[Any], Any]] = None, + builtin_types: Iterable[type] | None = None, + enc_hook: Callable[[Any], Any] | None = None, order: Literal[None, "deterministic", "sorted"] = None, ) -> Any: ... @overload def convert( obj: Any, - type: Type[T], + type: type[T], *, strict: bool = True, from_attributes: bool = False, - dec_hook: Optional[Callable[[type, Any], Any]] = None, - builtin_types: Union[Iterable[type], None] = None, + dec_hook: Callable[[type, Any], Any] | None = None, + builtin_types: Iterable[type] | None = None, str_keys: bool = False, ) -> T: ... @overload @@ -218,8 +205,8 @@ def convert( *, strict: bool = True, from_attributes: bool = False, - dec_hook: Optional[Callable[[type, Any], Any]] = None, - builtin_types: Union[Iterable[type], None] = None, + dec_hook: Callable[[type, Any], Any] | None = None, + builtin_types: Iterable[type] | None = None, str_keys: bool = False, ) -> Any: ... diff --git a/src/msgspec/_json_schema.py b/src/msgspec/_json_schema.py index 23b45c87..72a5e0bb 100644 --- a/src/msgspec/_json_schema.py +++ b/src/msgspec/_json_schema.py @@ -2,8 +2,8 @@ import re import textwrap -from collections.abc import Iterable -from typing import Any, Callable, Optional +from collections.abc import Callable, Iterable +from typing import Any from . import inspect as mi, to_builtins @@ -11,7 +11,7 @@ def schema( - type: Any, *, schema_hook: Optional[Callable[[type], dict[str, Any]]] = None + type: Any, *, schema_hook: Callable[[type], dict[str, Any]] | None = None ) -> dict[str, Any]: """Generate a JSON Schema for a given type. @@ -48,7 +48,7 @@ def schema( def schema_components( types: Iterable[Any], *, - schema_hook: Optional[Callable[[type], dict[str, Any]]] = None, + schema_hook: Callable[[type], dict[str, Any]] | None = None, ref_template: str = "#/$defs/{name}", ) -> tuple[tuple[dict[str, Any], ...], dict[str, Any]]: """Generate JSON Schemas for one or more types. @@ -201,7 +201,7 @@ class _SchemaGenerator: def __init__( self, name_map: dict[Any, str], - schema_hook: Optional[Callable[[type], dict[str, Any]]] = None, + schema_hook: Callable[[type], dict[str, Any]] | None = None, ref_template: str = "#/$defs/{name}", ): self.name_map = name_map diff --git a/src/msgspec/_typing_utils.pyi b/src/msgspec/_typing_utils.pyi index 98a41e3a..f81771cd 100644 --- a/src/msgspec/_typing_utils.pyi +++ b/src/msgspec/_typing_utils.pyi @@ -1,4 +1,4 @@ -from typing_extensions import TypeGuard +from typing import TypeGuard from . import Struct diff --git a/src/msgspec/_utils.py b/src/msgspec/_utils.py index 4763e072..5ddca42c 100644 --- a/src/msgspec/_utils.py +++ b/src/msgspec/_utils.py @@ -159,11 +159,6 @@ def get_class_annotations(obj): set: set, frozenset: frozenset, dict: dict, - typing.List: list, - typing.Tuple: tuple, - typing.Set: set, - typing.FrozenSet: frozenset, - typing.Dict: dict, typing.Collection: list, typing.MutableSequence: list, typing.Sequence: list, diff --git a/src/msgspec/inspect.py b/src/msgspec/inspect.py index 805fa29a..13cc53e3 100644 --- a/src/msgspec/inspect.py +++ b/src/msgspec/inspect.py @@ -9,8 +9,6 @@ Any, Final, Literal, - Tuple, - Type as typing_Type, TypeVar, Union, ) @@ -107,8 +105,8 @@ class Metadata(Type): """ type: Type - extra_json_schema: Union[dict, None] = None - extra: Union[dict, None] = None + extra_json_schema: dict | None = None + extra: dict | None = None class AnyType(Type): @@ -140,11 +138,11 @@ class IntType(Type): If set, an instance of this type must be a multiple of ``multiple_of``. """ - gt: Union[int, None] = None - ge: Union[int, None] = None - lt: Union[int, None] = None - le: Union[int, None] = None - multiple_of: Union[int, None] = None + gt: int | None = None + ge: int | None = None + lt: int | None = None + le: int | None = None + multiple_of: int | None = None class FloatType(Type): @@ -164,11 +162,11 @@ class FloatType(Type): If set, an instance of this type must be a multiple of ``multiple_of``. """ - gt: Union[float, None] = None - ge: Union[float, None] = None - lt: Union[float, None] = None - le: Union[float, None] = None - multiple_of: Union[float, None] = None + gt: float | None = None + ge: float | None = None + lt: float | None = None + le: float | None = None + multiple_of: float | None = None class StrType(Type): @@ -187,9 +185,9 @@ class StrType(Type): Note that the pattern is treated as **unanchored**. """ - min_length: Union[int, None] = None - max_length: Union[int, None] = None - pattern: Union[str, None] = None + min_length: int | None = None + max_length: int | None = None + pattern: str | None = None class BytesType(Type): @@ -205,8 +203,8 @@ class BytesType(Type): to ``max_length``. """ - min_length: Union[int, None] = None - max_length: Union[int, None] = None + min_length: int | None = None + max_length: int | None = None class ByteArrayType(Type): @@ -222,8 +220,8 @@ class ByteArrayType(Type): to ``max_length``. """ - min_length: Union[int, None] = None - max_length: Union[int, None] = None + min_length: int | None = None + max_length: int | None = None class MemoryViewType(Type): @@ -239,8 +237,8 @@ class MemoryViewType(Type): to ``max_length``. """ - min_length: Union[int, None] = None - max_length: Union[int, None] = None + min_length: int | None = None + max_length: int | None = None class DateTimeType(Type): @@ -255,7 +253,7 @@ class DateTimeType(Type): accepts either timezone-aware or timezone-naive values. """ - tz: Union[bool, None] = None + tz: bool | None = None class TimeType(Type): @@ -270,7 +268,7 @@ class TimeType(Type): accepts either timezone-aware or timezone-naive values. """ - tz: Union[bool, None] = None + tz: bool | None = None class DateType(Type): @@ -306,7 +304,7 @@ class EnumType(Type): The corresponding `enum.Enum` type. """ - cls: typing_Type[enum.Enum] + cls: type[enum.Enum] class LiteralType(Type): @@ -319,7 +317,7 @@ class LiteralType(Type): `int` literals are supported. """ - values: Union[Tuple[str, ...], Tuple[int, ...]] + values: tuple[str, ...] | tuple[int, ...] class CustomType(Type): @@ -343,7 +341,7 @@ class UnionType(Type): A tuple of possible types for this union. """ - types: Tuple[Type, ...] + types: tuple[Type, ...] @property def includes_none(self) -> bool: @@ -370,8 +368,8 @@ class CollectionType(Type): """ item_type: Type - min_length: Union[int, None] = None - max_length: Union[int, None] = None + min_length: int | None = None + max_length: int | None = None class ListType(CollectionType): @@ -447,7 +445,7 @@ class TupleType(Type): A tuple of types for each element in the tuple. """ - item_types: Tuple[Type, ...] + item_types: tuple[Type, ...] class DictType(Type): @@ -469,8 +467,8 @@ class DictType(Type): key_type: Type value_type: Type - min_length: Union[int, None] = None - max_length: Union[int, None] = None + min_length: int | None = None + max_length: int | None = None class Field(msgspec.Struct): @@ -517,7 +515,7 @@ class TypedDictType(Type): """ cls: type - fields: Tuple[Field, ...] + fields: tuple[Field, ...] class NamedTupleType(Type): @@ -532,7 +530,7 @@ class NamedTupleType(Type): """ cls: type - fields: Tuple[Field, ...] + fields: tuple[Field, ...] class DataclassType(Type): @@ -547,7 +545,7 @@ class DataclassType(Type): """ cls: type - fields: Tuple[Field, ...] + fields: tuple[Field, ...] class StructType(Type): @@ -570,10 +568,10 @@ class StructType(Type): ``True`` any unknown fields will result in an error. """ - cls: typing_Type[msgspec.Struct] - fields: Tuple[Field, ...] - tag_field: Union[str, None] = None - tag: Union[str, int, None] = None + cls: type[msgspec.Struct] + fields: tuple[Field, ...] + tag_field: str | None = None + tag: str | int | None = None array_like: bool = False forbid_unknown_fields: bool = False @@ -740,7 +738,7 @@ def run(self): # First construct a decoder to validate the types are valid from ._core import MsgpackDecoder - MsgpackDecoder(Tuple[self.types]) + MsgpackDecoder(tuple[self.types]) return tuple(self.translate(t) for t in self.types) def translate(self, typ): diff --git a/src/msgspec/json.pyi b/src/msgspec/json.pyi index dc9172ed..d951f7e8 100644 --- a/src/msgspec/json.pyi +++ b/src/msgspec/json.pyi @@ -1,14 +1,9 @@ from collections.abc import Callable, Iterable from typing import ( Any, - Dict, Generic, Literal, - Optional, - Tuple, - Type, TypeVar, - Union, overload, ) @@ -16,10 +11,10 @@ from typing_extensions import Buffer T = TypeVar("T") -enc_hook_sig = Optional[Callable[[Any], Any]] -dec_hook_sig = Optional[Callable[[type, Any], Any]] -float_hook_sig = Optional[Callable[[str], Any]] -schema_hook_sig = Optional[Callable[[type], dict[str, Any]]] +enc_hook_sig = Callable[[Any], Any] | None +dec_hook_sig = Callable[[type, Any], Any] | None +float_hook_sig = Callable[[str], Any] | None +schema_hook_sig = Callable[[type], dict[str, Any]] | None class Encoder: enc_hook: enc_hook_sig @@ -38,11 +33,11 @@ class Encoder: def encode(self, obj: Any, /) -> bytes: ... def encode_lines(self, items: Iterable, /) -> bytes: ... def encode_into( - self, obj: Any, buffer: bytearray, offset: Optional[int] = 0, / + self, obj: Any, buffer: bytearray, offset: int | None = 0, / ) -> None: ... class Decoder(Generic[T]): - type: Type[T] + type: type[T] strict: bool dec_hook: dec_hook_sig float_hook: float_hook_sig @@ -58,7 +53,7 @@ class Decoder(Generic[T]): @overload def __init__( self: Decoder[T], - type: Type[T] = ..., + type: type[T] = ..., *, strict: bool = True, dec_hook: dec_hook_sig = None, @@ -73,12 +68,12 @@ class Decoder(Generic[T]): dec_hook: dec_hook_sig = None, float_hook: float_hook_sig = None, ) -> None: ... - def decode(self, buf: Union[Buffer, str], /) -> T: ... - def decode_lines(self, buf: Union[Buffer, str], /) -> list[T]: ... + def decode(self, buf: Buffer | str, /) -> T: ... + def decode_lines(self, buf: Buffer | str, /) -> list[T]: ... @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, /, *, strict: bool = True, @@ -86,16 +81,16 @@ def decode( ) -> Any: ... @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, /, *, - type: Type[T] = ..., + type: type[T] = ..., strict: bool = True, dec_hook: dec_hook_sig = None, ) -> T: ... @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, /, *, type: Any = ..., @@ -109,13 +104,13 @@ def encode( enc_hook: enc_hook_sig = None, order: Literal[None, "deterministic", "sorted"] = None, ) -> bytes: ... -def schema(type: Any, *, schema_hook: schema_hook_sig = None) -> Dict[str, Any]: ... +def schema(type: Any, *, schema_hook: schema_hook_sig = None) -> dict[str, Any]: ... def schema_components( types: Iterable[Any], *, schema_hook: schema_hook_sig = None, ref_template: str = "#/$defs/{name}", -) -> Tuple[Tuple[Dict[str, Any], ...], Dict[str, Any]]: ... +) -> tuple[tuple[dict[str, Any], ...], dict[str, Any]]: ... @overload def format(buf: str, /, *, indent: int = 2) -> str: ... @overload diff --git a/src/msgspec/msgpack.pyi b/src/msgspec/msgpack.pyi index 4eb5e38d..9ba642a8 100644 --- a/src/msgspec/msgpack.pyi +++ b/src/msgspec/msgpack.pyi @@ -1,12 +1,9 @@ +from collections.abc import Callable from typing import ( Any, - Callable, Generic, Literal, - Optional, - Type, TypeVar, - Union, overload, ) @@ -14,19 +11,17 @@ from typing_extensions import Buffer T = TypeVar("T") -enc_hook_sig = Optional[Callable[[Any], Any]] -ext_hook_sig = Optional[Callable[[int, memoryview], Any]] -dec_hook_sig = Optional[Callable[[type, Any], Any]] +enc_hook_sig = Callable[[Any], Any] | None +ext_hook_sig = Callable[[int, memoryview], Any] | None +dec_hook_sig = Callable[[type, Any], Any] | None class Ext: code: int - data: Union[bytes, bytearray, memoryview] - def __init__( - self, code: int, data: Union[bytes, bytearray, memoryview] - ) -> None: ... + data: bytes | bytearray | memoryview + def __init__(self, code: int, data: bytes | bytearray | memoryview) -> None: ... class Decoder(Generic[T]): - type: Type[T] + type: type[T] strict: bool dec_hook: dec_hook_sig ext_hook: ext_hook_sig @@ -41,7 +36,7 @@ class Decoder(Generic[T]): @overload def __init__( self: Decoder[T], - type: Type[T] = ..., + type: type[T] = ..., *, strict: bool = True, dec_hook: dec_hook_sig = None, @@ -73,7 +68,7 @@ class Encoder: ): ... def encode(self, obj: Any, /) -> bytes: ... def encode_into( - self, obj: Any, buffer: bytearray, offset: Optional[int] = 0, / + self, obj: Any, buffer: bytearray, offset: int | None = 0, / ) -> None: ... @overload @@ -90,7 +85,7 @@ def decode( buf: Buffer, /, *, - type: Type[T] = ..., + type: type[T] = ..., strict: bool = True, dec_hook: dec_hook_sig = None, ext_hook: ext_hook_sig = None, diff --git a/src/msgspec/structs.pyi b/src/msgspec/structs.pyi index 6be562be..147edb9d 100644 --- a/src/msgspec/structs.pyi +++ b/src/msgspec/structs.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, Union +from typing import Any, TypeVar from . import NODEFAULT, Struct @@ -21,8 +21,8 @@ class StructConfig: weakref: bool dict: bool cache_hash: bool - tag: Union[str, int, None] - tag_field: Union[str, None] + tag: str | int | None + tag_field: str | None class FieldInfo(Struct): name: str diff --git a/src/msgspec/toml.py b/src/msgspec/toml.py index 802bfce4..b2edb832 100644 --- a/src/msgspec/toml.py +++ b/src/msgspec/toml.py @@ -10,7 +10,8 @@ ) if TYPE_CHECKING: - from typing import Callable, Literal, Optional, Type, Union + from collections.abc import Callable + from typing import Literal from typing_extensions import Buffer @@ -60,7 +61,7 @@ def _import_tomli_w(): def encode( obj: Any, *, - enc_hook: Optional[Callable[[Any], Any]] = None, + enc_hook: Callable[[Any], Any] | None = None, order: Literal[None, "deterministic", "sorted"] = None, ) -> bytes: """Serialize an object as TOML. @@ -111,32 +112,32 @@ def encode( @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, *, strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> Any: pass @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, *, - type: Type[T] = ..., + type: type[T] = ..., strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> T: pass @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, *, type: Any = ..., strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> Any: pass diff --git a/src/msgspec/yaml.py b/src/msgspec/yaml.py index d9942290..02f8bb3c 100644 --- a/src/msgspec/yaml.py +++ b/src/msgspec/yaml.py @@ -10,7 +10,8 @@ ) if TYPE_CHECKING: - from typing import Callable, Literal, Optional, Type, Union + from collections.abc import Callable + from typing import Literal from typing_extensions import Buffer @@ -39,7 +40,7 @@ def _import_pyyaml(name): def encode( obj: Any, *, - enc_hook: Optional[Callable[[Any], Any]] = None, + enc_hook: Callable[[Any], Any] | None = None, order: Literal[None, "deterministic", "sorted"] = None, ) -> bytes: """Serialize an object as YAML. @@ -104,32 +105,32 @@ def encode( @overload def decode( - buf: Union[Buffer, str], + buf: Buffer | str, *, strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> Any: pass @overload def decode( - buf: Union[bytes, str], + buf: bytes | str, *, - type: Type[T] = ..., + type: type[T] = ..., strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> T: pass @overload def decode( - buf: Union[bytes, str], + buf: bytes | str, *, type: Any = ..., strict: bool = True, - dec_hook: Optional[Callable[[type, Any], Any]] = None, + dec_hook: Callable[[type, Any], Any] | None = None, ) -> Any: pass