4545from . import ansi , constants , plugin , utils
4646from .argparse_custom import DEFAULT_ARGUMENT_PARSER , CompletionItem
4747from .clipboard import can_clip , get_paste_buffer , write_to_paste_buffer
48- from .command_definition import CommandSet , _partial_passthru
48+ from .command_definition import CommandSet
4949from .constants import COMMAND_FUNC_PREFIX , COMPLETER_FUNC_PREFIX , HELP_FUNC_PREFIX
5050from .decorators import with_argparser , as_subcommand_to
5151from .exceptions import (
@@ -186,7 +186,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
186186 :param auto_load_commands: If True, cmd2 will check for all subclasses of `CommandSet`
187187 that are currently loaded by Python and automatically
188188 instantiate and register all commands. If False, CommandSets
189- must be manually installed with `install_command_set `.
189+ must be manually installed with `register_command_set `.
190190 """
191191 # If use_ipython is False, make sure the ipy command isn't available in this instance
192192 if not use_ipython :
@@ -264,7 +264,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
264264 self ._cmd_to_command_sets = {} # type: Dict[str, CommandSet]
265265 if command_sets :
266266 for command_set in command_sets :
267- self .install_command_set (command_set )
267+ self .register_command_set (command_set )
268268
269269 if auto_load_commands :
270270 self ._autoload_commands ()
@@ -452,11 +452,11 @@ def load_commandset_by_type(commandset_types: List[Type]) -> None:
452452 or len (init_sig .parameters ) != 1
453453 or 'self' not in init_sig .parameters ):
454454 cmdset = cmdset_type ()
455- self .install_command_set (cmdset )
455+ self .register_command_set (cmdset )
456456
457457 load_commandset_by_type (all_commandset_defs )
458458
459- def install_command_set (self , cmdset : CommandSet ) -> None :
459+ def register_command_set (self , cmdset : CommandSet ) -> None :
460460 """
461461 Installs a CommandSet, loading all commands defined in the CommandSet
462462
@@ -476,23 +476,20 @@ def install_command_set(self, cmdset: CommandSet) -> None:
476476 try :
477477 for method_name , method in methods :
478478 command = method_name [len (COMMAND_FUNC_PREFIX ):]
479- command_wrapper = _partial_passthru (method , self )
480479
481- self ._install_command_function (command , command_wrapper , type (cmdset ).__name__ )
480+ self ._install_command_function (command , method , type (cmdset ).__name__ )
482481 installed_attributes .append (method_name )
483482
484483 completer_func_name = COMPLETER_FUNC_PREFIX + command
485484 cmd_completer = getattr (cmdset , completer_func_name , None )
486485 if cmd_completer is not None :
487- completer_wrapper = _partial_passthru (cmd_completer , self )
488- self ._install_completer_function (command , completer_wrapper )
486+ self ._install_completer_function (command , cmd_completer )
489487 installed_attributes .append (completer_func_name )
490488
491489 help_func_name = HELP_FUNC_PREFIX + command
492490 cmd_help = getattr (cmdset , help_func_name , None )
493491 if cmd_help is not None :
494- help_wrapper = _partial_passthru (cmd_help , self )
495- self ._install_help_function (command , help_wrapper )
492+ self ._install_help_function (command , cmd_help )
496493 installed_attributes .append (help_func_name )
497494
498495 self ._cmd_to_command_sets [command ] = cmdset
@@ -508,7 +505,7 @@ def install_command_set(self, cmdset: CommandSet) -> None:
508505 if cmdset in self ._cmd_to_command_sets .values ():
509506 self ._cmd_to_command_sets = \
510507 {key : val for key , val in self ._cmd_to_command_sets .items () if val is not cmdset }
511- cmdset .on_unregister (self )
508+ cmdset .on_unregister ()
512509 raise
513510
514511 def _install_command_function (self , command : str , command_wrapper : Callable , context = '' ):
@@ -549,7 +546,7 @@ def _install_help_function(self, cmd_name: str, cmd_help: Callable):
549546 raise CommandSetRegistrationError ('Attribute already exists: {}' .format (help_func_name ))
550547 setattr (self , help_func_name , cmd_help )
551548
552- def uninstall_command_set (self , cmdset : CommandSet ):
549+ def unregister_command_set (self , cmdset : CommandSet ):
553550 """
554551 Uninstalls a CommandSet and unloads all associated commands
555552 :param cmdset: CommandSet to uninstall
@@ -581,7 +578,7 @@ def uninstall_command_set(self, cmdset: CommandSet):
581578 if hasattr (self , HELP_FUNC_PREFIX + cmd_name ):
582579 delattr (self , HELP_FUNC_PREFIX + cmd_name )
583580
584- cmdset .on_unregister (self )
581+ cmdset .on_unregister ()
585582 self ._installed_command_sets .remove (cmdset )
586583
587584 def _check_uninstallable (self , cmdset : CommandSet ):
@@ -656,11 +653,7 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
656653 raise CommandSetRegistrationError ('Could not find argparser for command "{}" needed by subcommand: {}'
657654 .format (command_name , str (method )))
658655
659- if isinstance (cmdset , CommandSet ):
660- command_handler = _partial_passthru (method , self )
661- else :
662- command_handler = method
663- subcmd_parser .set_defaults (cmd2_handler = command_handler )
656+ subcmd_parser .set_defaults (cmd2_handler = method )
664657
665658 def find_subcommand (action : argparse .ArgumentParser , subcmd_names : List [str ]) -> argparse .ArgumentParser :
666659 if not subcmd_names :
0 commit comments