summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2021-03-02 20:43:33 -0500
committerGitHub <noreply@github.com>2021-03-02 20:43:33 -0500
commit462e1623ff2b7c47643dc50023837e07265a87fc (patch)
treeb92111657b64943bb3114820a712908fe5d79d80 /cmd2
parentcc9d96a7c5309bec64856e4dd9554d2cee235d23 (diff)
parent5732bc3cc7a9e97b496006c90eaf07a55ee35095 (diff)
downloadcmd2-git-462e1623ff2b7c47643dc50023837e07265a87fc.tar.gz
Merge pull request #1069 from python-cmd2/completion_item_choices
Fixed issue where argparse choices could not be CompletionItems
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/argparse_completer.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 21007289..ef35eabc 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -641,8 +641,11 @@ class ArgparseCompleter:
arg_choices.sort()
self._cmd2_app.matches_sorted = True
- # Since choices can be various types, convert them all to strings
- arg_choices = [str(x) for x in arg_choices]
+ # Since choices can be various types, make sure they are all strings
+ for index, choice in enumerate(arg_choices):
+ # Prevent converting anything that is already a str (i.e. CompletionItem)
+ if not isinstance(choice, str):
+ arg_choices[index] = str(choice)
else:
arg_choices = getattr(arg_state.action, ATTR_CHOICES_CALLABLE, None)
if arg_choices is None: