diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-03 11:39:00 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-03 11:39:00 -0400 |
commit | 43609217b1218cbe0654965e01357f707fe287af (patch) | |
tree | 9f08ff916e01d8c4f739479d943f612f66ca8923 | |
parent | e6d319185d5000c36b452c048fcb9f8746955280 (diff) | |
parent | d9a71279762b19157841fa09a238a39c2b97b66f (diff) | |
download | cmd2-git-43609217b1218cbe0654965e01357f707fe287af.tar.gz |
Merge branch 'master' into auto_completer_refactor
-rw-r--r-- | cmd2/cmd2.py | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 27ff16c8..ac9cdb6a 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: @@ -955,8 +932,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 = utils.basic_complete(text, line, begidx, endidx, match_against) # Perform tab completion using a function @@ -999,8 +976,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 = utils.basic_complete(text, line, begidx, endidx, match_against) # Perform tab completion using a function |