Skip to content

Commit

Permalink
Fix decorator for typing of existing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed Oct 7, 2024
1 parent 2a115ca commit 4aec990
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions twitchio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,17 @@ def decorator(func: F) -> F:
def wrapper(*args: Any, **kwargs: Any) -> Any:
from .user import PartialUser

new_args = [(arg.id if isinstance(arg, PartialUser) else arg) for arg in (args[1:] if is_self else args)]
if is_self:
new_args = [args[0], *new_args]
new_kwargs = {k: (v.id if isinstance(v, PartialUser) else v) for k, v in kwargs.items()}
new_args = [
(str(arg.id) if isinstance(arg, PartialUser) else arg)
for i, arg in enumerate(args)
if not (is_self and i == 0)
]

if is_self and args:
new_args.insert(0, args[0])

new_kwargs = {k: (str(v.id) if isinstance(v, PartialUser) else v) for k, v in kwargs.items()}

return func(*new_args, **new_kwargs)

return cast(F, wrapper)
Expand Down

0 comments on commit 4aec990

Please sign in to comment.