Skip to content

[BUG] Crash on autocompletion #155

Description

@AlAtsal

Crash on autocompletion: AttributeError: 'list' object has no attribute 'to_strings'

Describe the bug

When attempting to trigger autocompletion (by pressing TAB twice) in the CLI, the application crashes with an AttributeError.

Traceback

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
  │ /home/aatsalak/repos/quads-client/venv/lib64/python3.14/site-packages/cmd2/cmd2.py:2683 in        │
  │ complete                                                                                         │
  │                                                                                                  │
  │   2680 │   │   │   │   )                                                                             │
  │   2681 │   │   │   │   custom_settings = utils.CustomCompletionSettings(parser)                      │
  │   2682 │   │   │   │                                                                                 │
  │ ❱ 2683 │   │   │   │   completions = self._perform_completion(text, line, begidx, endidx,            │
  │        custom_settings)                                                                          │
  │   2684 │   │   │   │                                                                                 │
  │   2685 │   │   │   │   # Check if we need to restore a shortcut in the completion text                │
  │   2686 │   │   │   │   # so it doesn't get erased from the command line.                             │
  │                                                                                                  │
  │ /home/aatsalak/repos/quads-client/venv/lib64/python3.14/site-packages/cmd2/cmd2.py:2609 in        │
  │ _perform_completion                                                                              │
  │                                                                                                  │
  │   2606 │   │                                                                                     │
  │   2607 │   │   # Check if we need to add an opening quote                                        │
  │   2608 │   │   if not completion_token_quote:                                                    │
  │ ❱ 2609 │   │   │   matches = completions.to_strings()                                            │
  │   2610 │   │   │                                                                                     │
  │   2611 │   │   │   if any(" " in match for match in matches):                                        │
  │   2612 │   │   │   │   _add_opening_quote = True                                                     │
  ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
  AttributeError: 'list' object has no attribute 'to_strings'

Root Cause

This is caused by changes introduced in the cmd2 4.x completion API. The complete_* methods must now return cmd2.CompletionItem objects (which have .to_strings() method) instead of plain lists.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions