Skip to content

Commit

Permalink
fix: Call to untyped function "serde" in typed context
Browse files Browse the repository at this point in the history
  • Loading branch information
yukinarit committed Aug 27, 2022
1 parent d42e058 commit 84c5f07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
35 changes: 31 additions & 4 deletions serde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,27 @@
"""

from dataclasses import dataclass
from typing import Callable, Optional, Type, overload

from .compat import SerdeError, SerdeSkip
from .compat import SerdeError, SerdeSkip, T
from .core import (
AdjacentTagging,
Coerce,
DefaultTagging,
ExternalTagging,
InternalTagging,
NoCheck,
Strict,
Tagging,
TypeCheck,
Untagged,
field,
init,
logger,
should_impl_dataclass,
)
from .de import default_deserializer, deserialize, from_dict, from_tuple, is_deserializable
from .se import asdict, astuple, default_serializer, is_serializable, serialize, to_dict, to_tuple
from .de import DeserializeFunc, default_deserializer, deserialize, from_dict, from_tuple, is_deserializable
from .se import SerializeFunc, asdict, astuple, default_serializer, is_serializable, serialize, to_dict, to_tuple

__all__ = (
"SerdeError",
Expand Down Expand Up @@ -102,7 +106,30 @@
)


def serde(_cls=None, **kwargs):
@overload
def serde(
_cls: Type[T],
) -> Type[T]:
...


@overload
def serde(
rename_all: Optional[str] = None,
reuse_instances_default: bool = True,
convert_sets_default: bool = False,
serializer: Optional[SerializeFunc] = None,
deserializer: Optional[DeserializeFunc] = None,
tagging: Tagging = DefaultTagging,
type_check: TypeCheck = NoCheck,
) -> Callable[[Type[T]], Type[T]]:
...


def serde(
_cls=None,
**kwargs,
): # type: ignore
"""
serde decorator. Keyword arguments are passed in `serialize` and `deserialize`.
"""
Expand Down
2 changes: 1 addition & 1 deletion serde/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _make_deserialize(
C = dataclasses.make_dataclass(cls_name, fields, *args, **kwargs)
C = deserialize(
C,
*args,
rename_all=rename_all,
reuse_instances_default=reuse_instances_default,
convert_sets_default=convert_sets_default,
Expand All @@ -136,6 +135,7 @@ def deserialize(
_cls=None,
rename_all: Optional[str] = None,
reuse_instances_default: bool = True,
convert_sets_default: bool = False,
deserializer: Optional[DeserializeFunc] = None,
tagging: Tagging = DefaultTagging,
type_check: TypeCheck = NoCheck,
Expand Down
1 change: 0 additions & 1 deletion serde/se.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _make_serialize(
C = dataclasses.make_dataclass(cls_name, fields, *args, **kwargs)
C = serialize(
C,
*args,
rename_all=rename_all,
reuse_instances_default=reuse_instances_default,
convert_sets_default=convert_sets_default,
Expand Down

0 comments on commit 84c5f07

Please sign in to comment.