diff options
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index a10219b1..4b0304fd 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -40,7 +40,7 @@ import sys import threading from collections import namedtuple from contextlib import redirect_stdout -from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, Union +from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, Type, Union from . import ansi from . import constants @@ -80,29 +80,6 @@ else: rl_basic_quote_characters = ctypes.c_char_p.in_dll(readline_lib, "rl_basic_quote_characters") orig_rl_basic_quotes = ctypes.cast(rl_basic_quote_characters, ctypes.c_void_p).value -# Collection is a container that is sizable and iterable -# It was introduced in Python 3.6. We will try to import it, otherwise use our implementation -try: - from collections.abc import Collection, Iterable -except ImportError: - from collections.abc import Sized, Iterable, Container - - # noinspection PyAbstractClass - class Collection(Sized, Iterable, Container): - - __slots__ = () - - # noinspection PyPep8Naming - @classmethod - def __subclasshook__(cls, C): - if cls is Collection: - if any("__len__" in B.__dict__ for B in C.__mro__) and \ - any("__iter__" in B.__dict__ for B in C.__mro__) and \ - any("__contains__" in B.__dict__ for B in C.__mro__): - return True - return NotImplemented - - # Detect whether IPython is installed to determine if the built-in "ipy" command should be included ipython_available = True try: @@ -969,8 +946,8 @@ class Cmd(cmd.Cmd): if flag in flag_dict: match_against = flag_dict[flag] - # Perform tab completion using a Collection - if isinstance(match_against, Collection): + # Perform tab completion using an Iterable + if isinstance(match_against, Iterable): completions_matches = self.basic_complete(text, line, begidx, endidx, match_against) # Perform tab completion using a function @@ -1013,8 +990,8 @@ class Cmd(cmd.Cmd): else: match_against = all_else - # Perform tab completion using a Collection - if isinstance(match_against, Collection): + # Perform tab completion using a Iterable + if isinstance(match_against, Iterable): matches = self.basic_complete(text, line, begidx, endidx, match_against) # Perform tab completion using a function @@ -3183,7 +3160,7 @@ class Cmd(cmd.Cmd): readline.set_completion_display_matches_hook(None) elif rl_type == RlType.PYREADLINE: # noinspection PyUnresolvedReferences - readline.rl.mode._display_completions = self._display_matches_pyreadline + readline.rl.mode._display_completions = orig_pyreadline_display # Save off the current completer and set a new one in the Python console # Make sure it tab completes from its locals() dictionary |