Skip to content

Commit

Permalink
Fix type hint of add_objprint (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian authored Oct 22, 2024
1 parent 7b27b20 commit 02600bb
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/objprint/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@


import functools
from typing import Callable, Optional, Type, Set, Union
from typing import Callable, Optional, Type, TypeVar, Set, Union, overload


T = TypeVar("T", bound=Type)


@overload
def add_objprint(
orig_class: None = None,
format: str = "string", **kwargs) -> Callable[[T], T]:
...


@overload
def add_objprint(
orig_class: T,
format: str = "string", **kwargs) -> T:
...


def add_objprint(
orig_class: Optional[Type] = None,
format: str = "string", **kwargs) -> Union[Type, Callable[[Type], Type]]:
orig_class: Optional[T] = None,
format: str = "string", **kwargs) -> Union[T, Callable[[T], T]]:

from . import _objprint

Expand All @@ -24,7 +41,7 @@ def __str__(self) -> str:
return _objprint._get_custom_object_str(self, memo, indent_level=0, cfg=cfg)

if orig_class is None:
def wrapper(cls: Type) -> Type:
def wrapper(cls: T) -> T:
cls.__str__ = functools.wraps(cls.__str__)(__str__) # type: ignore
return cls
return wrapper
Expand Down

0 comments on commit 02600bb

Please sign in to comment.