Skip to content
This repository was archived by the owner on Aug 29, 2021. It is now read-only.

Commit 7743992

Browse files
committed
[fix] CCmd not copying
1 parent ca8a5fd commit 7743992

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

disctools/__version_info__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __repr__(self) -> str:
2020
}
2121

2222
class last_modified:
23-
day = 13
23+
day = 17
2424
month = 5
2525
year = 2021
2626

@@ -93,7 +93,7 @@ def __repr__(self) -> str:
9393
version_info = VersionInfo(
9494
major = 0,
9595
minor = 5,
96-
patch = 1,
96+
patch = 2,
9797
status = status_map["final"],
9898
)
9999

disctools/commands.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@ class CCmd(Command[Context], _Group, metaclass=CogCommandType, _root=True):
398398
399399
Also called :class:`CogCmd`
400400
"""
401-
def __init__(self, func: Optional[AsyncCallable] = None, **kwargs):
402-
super().__init__(func=func, **kwargs)
403-
for i in self.__class__.__fut_sub_cmds__.values():
404-
# -- Let errors be raised ; DESC:: [This handles all the stuff that is
405-
self.add_command(i) # usually done for an instance in a cog]
406-
i.cogcmd = self
401+
def copy(self):
402+
ret = super(Command, self).copy()
403+
for cmd in map(lambda x: x.copy(), self.commands):
404+
ret.add_command(cmd)
405+
cmd.cogcmd = ret
406+
return ret
407407

408408
async def on_subcommand_error(self, ctx: Context, error: CommandError) -> Any:
409409
"""|overridecoro|
@@ -431,7 +431,7 @@ async def subcommand_after_invoke(self, ctx: Context) -> Any:
431431

432432
## Decorators ##
433433

434-
G = TypeVar("G", bound=_Command)
434+
G = TypeVar("G", bound=Command)
435435

436436
def inject(**kwargs) -> Callable[[Type[G]], G]:
437437
"""This is a Decorator.
@@ -466,5 +466,10 @@ class MyCmd(Command):
466466
def decorator(cls: Type[G]) -> G:
467467
if isinstance(cls, _Command):
468468
raise TypeError("Can not inject a command instance, expected a <class 'type'>")
469+
if issubclass(cls, CCmd):
470+
self = cls(**kwargs)
471+
for i in cls.__fut_sub_cmds__.values():
472+
self.add_command(i)
473+
i.cogcmd = self
469474
return cls(**kwargs)
470475
return decorator

version.num

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.1
1+
0.5.2

0 commit comments

Comments
 (0)