осторожноfrom functools import wraps, partial
def command(**cmdargs):
def _run(func):
@wraps(func)
def wrapper(self, *args):
return partial(func, self, args, cmdargs)
return wrapper
return _run
class Aliases:
@property
def commands(self) -> tuple:
return (
self.new_alias(),
)
@command(
command="новый алиас",
args={"алиас": "str"}
)
def new_alias(self, *args):
for arg in args:
if isinstance(arg, str): # заменить на types.Message):
return arg
return args
>>> aliases = Aliases()
>>> aliases.commands
(functools.partial(<function Aliases.new_alias at 0x778154c550>, <__main__.Aliases object at 0x778205af50>, (), {'command': 'новый алиас', 'args': {'алиас': 'str'}}),)
>>> aliases.commands[0]
functools.partial(<function Aliases.new_alias at 0x778154c550>, <__main__.Aliases object at 0x778205af50>, (), {'command': 'новый алиас', 'args': {'алиас': 'str'}})
>>> aliases.commands[0].args[2]
{'command': 'новый алиас', 'args': {'алиас': 'str'}}
>>> aliases.commands[0]("types.Message object")
'types.Message object'