Skip to content

Improve method annotations #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cattrs/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(
# Unions are instances now, not classes. We use different registries.
self._union_struct_registry: Dict[Any, Callable[[Any, Type[T]], T]] = {}

def unstructure(self, obj: Any, unstructure_as=None) -> Any:
def unstructure(self, obj: Any, unstructure_as: Optional[type] = None) -> Any:
return self._unstructure_func.dispatch(
obj.__class__ if unstructure_as is None else unstructure_as
)(obj)
Expand All @@ -198,7 +198,7 @@ def unstruct_strat(self) -> UnstructureStrategy:
else UnstructureStrategy.AS_TUPLE
)

def register_unstructure_hook(self, cls: Any, func: Callable[[T], Any]) -> None:
def register_unstructure_hook(self, cls: Type[T], func: Callable[[T], Any]) -> None:
"""Register a class-to-primitive converter function for a class.

The converter function should take an instance of the class and return
Expand Down Expand Up @@ -235,7 +235,7 @@ def register_unstructure_hook_factory(
"""
self._unstructure_func.register_func_list([(predicate, factory, True)])

def register_structure_hook(self, cl: Any, func: Callable[[Any, Type[T]], T]):
def register_structure_hook(self, cl: Type[T], func: Callable[[Any, Type[T]], T]):
"""Register a primitive-to-class converter function for a type.

The converter function should take two arguments:
Expand Down