Verify the integrity of completion table data. :raises ValueError: if there is an error with the data.
(arg_state: _ArgumentState, completions: Completions)
| 572 | |
| 573 | @staticmethod |
| 574 | def _validate_table_data(arg_state: _ArgumentState, completions: Completions) -> None: |
| 575 | """Verify the integrity of completion table data. |
| 576 | |
| 577 | :raises ValueError: if there is an error with the data. |
| 578 | """ |
| 579 | table_columns = arg_state.action.get_table_columns() # type: ignore[attr-defined] |
| 580 | has_table_data = any(item.table_data for item in completions) |
| 581 | |
| 582 | if table_columns is None: |
| 583 | if has_table_data: |
| 584 | raise ValueError( |
| 585 | f"Argument '{arg_state.action.dest}' has CompletionItems with table_data, " |
| 586 | f"but no table_columns were defined in add_argument()." |
| 587 | ) |
| 588 | return |
| 589 | |
| 590 | # If columns are defined, then every item must have data, and lengths must match |
| 591 | for item in completions: |
| 592 | if not item.table_data: |
| 593 | raise ValueError( |
| 594 | f"Argument '{arg_state.action.dest}' has table_columns defined, " |
| 595 | f"but the CompletionItem for '{item.text}' is missing table_data." |
| 596 | ) |
| 597 | if len(item.table_data) != len(table_columns): |
| 598 | raise ValueError( |
| 599 | f"Argument '{arg_state.action.dest}': table_data length ({len(item.table_data)}) " |
| 600 | f"does not match table_columns length ({len(table_columns)}) for item '{item.text}'." |
| 601 | ) |
| 602 | |
| 603 | def _build_completion_table(self, arg_state: _ArgumentState, completions: Completions) -> Completions: |
| 604 | """Build a rich.Table for completion results if applicable.""" |
no outgoing calls