Skip to content

Commit 1a39513

Browse files
committed
Changed DisabledCommand into a namedtuple
1 parent 69ab1e1 commit 1a39513

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

cmd2/cmd2.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import re
3838
import sys
3939
import threading
40+
from collections import namedtuple
4041
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, Union, IO
4142

4243
import colorama
@@ -279,12 +280,8 @@ class EmptyStatement(Exception):
279280
pass
280281

281282

282-
class DisabledCommand:
283-
"""Contains data about a disabled command"""
284-
def __init__(self):
285-
# These are used to restore the original functions when the command is enabled
286-
self.command_function = None
287-
self.help_function = None
283+
# Contains data about a disabled command which is used to restore its original functions when the command is enabled
284+
DisabledCommand = namedtuple('DisabledCommand', ['command_function', 'help_function'])
288285

289286

290287
class Cmd(cmd.Cmd):
@@ -3673,10 +3670,8 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36733670
help_func_name = HELP_FUNC_PREFIX + command
36743671

36753672
# Add the disabled command record
3676-
dc = DisabledCommand()
3677-
dc.command_function = command_function
3678-
dc.help_function = getattr(self, help_func_name, None)
3679-
self.disabled_commands[command] = dc
3673+
self.disabled_commands[command] = DisabledCommand(command_function=command_function,
3674+
help_function=getattr(self, help_func_name, None))
36803675

36813676
# Overwrite the command and help functions to print the message
36823677
new_func = functools.partial(self._report_disabled_command_usage, message_to_print=message_to_print)

0 commit comments

Comments
 (0)