Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.16.9"
rev: "v0.16.10"
hooks:
- id: ruff-format
args: [--config=ruff.toml]
Expand Down
12 changes: 6 additions & 6 deletions cmd2/annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def _convert(value: str) -> enum.Enum:
raise _invalid_choice(value, _value_map)

_convert.__name__ = enum_class.__name__
_convert._cmd2_enum_class = enum_class # type: ignore[attr-defined, ty:unresolved-attribute]
_convert._cmd2_enum_class = enum_class # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
return _convert


Expand Down Expand Up @@ -989,7 +989,7 @@ def _unwrap_optional(tp: Any) -> tuple[Any, bool]:
there alone, so this helper never validates union members itself.
"""
origin = get_origin(tp)
if origin is Union or origin is types.UnionType: # type: ignore[comparison-overlap]
if origin is Union or origin is types.UnionType:
all_args = get_args(tp)
non_none = [a for a in all_args if a is not type(None)]
has_none = len(non_none) < len(all_args)
Expand All @@ -1014,14 +1014,14 @@ def _normalize_annotation(annotation: Any) -> _NormalizedAnnotation:
tp, unwrapped = _unwrap_optional(tp)
if unwrapped:
is_optional = True
if get_origin(tp) is Annotated: # type: ignore[comparison-overlap]
if get_origin(tp) is Annotated:
inner_tp = get_args(tp)[0]
inner_origin = get_origin(inner_tp)
inner_is_union = inner_origin is Union or inner_origin is types.UnionType # type: ignore[comparison-overlap]
inner_is_union = inner_origin is Union or inner_origin is types.UnionType
if not (inner_is_union and type(None) in get_args(inner_tp)):
raise TypeError("Annotated[T, meta] | None is ambiguous. Use Annotated[T | None, meta] instead.")

if get_origin(tp) is Annotated: # type: ignore[comparison-overlap]
if get_origin(tp) is Annotated:
args = get_args(tp)
tp = args[0]
for meta in args[1:]:
Expand Down Expand Up @@ -1119,7 +1119,7 @@ def _convert(value: str) -> Any:
_convert.__name__ = getattr(converter, "__name__", "preprocess")
enum_class = getattr(converter, "_cmd2_enum_class", None)
if enum_class is not None:
_convert._cmd2_enum_class = enum_class # type: ignore[attr-defined, ty:unresolved-attribute]
_convert._cmd2_enum_class = enum_class # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
return _convert


Expand Down
12 changes: 6 additions & 6 deletions cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
def _build_hint(parser: Cmd2ArgumentParser, arg_action: argparse.Action) -> str:
"""Build completion hint for a given argument."""
# Check if hinting is disabled for this argument
suppress_hint = arg_action.get_suppress_tab_hint() # type: ignore[attr-defined, ty:unresolved-attribute]
suppress_hint = arg_action.get_suppress_tab_hint() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if suppress_hint or arg_action.help == argparse.SUPPRESS:
return ""

Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, arg_action: argparse.Action) -> None:
self.is_remainder = self.action.nargs == argparse.REMAINDER

# Check if nargs is a range
nargs_range: tuple[int, int | float] | None = self.action.get_nargs_range() # type: ignore[attr-defined, ty:unresolved-attribute]
nargs_range: tuple[int, int | float] | None = self.action.get_nargs_range() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if nargs_range is not None:
self.min = nargs_range[0]
self.max = nargs_range[1]
Expand Down Expand Up @@ -575,7 +575,7 @@ def _validate_table_data(arg_state: _ArgumentState, completions: Completions) ->

:raises ValueError: if there is an error with the data.
"""
table_columns = arg_state.action.get_table_columns() # type: ignore[attr-defined, ty:unresolved-attribute]
table_columns = arg_state.action.get_table_columns() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
has_table_data = any(item.table_data for item in completions)

if table_columns is None:
Expand Down Expand Up @@ -606,7 +606,7 @@ def _build_completion_table(self, arg_state: _ArgumentState, completions: Comple

table_columns = cast(
Sequence[str | Column] | None,
arg_state.action.get_table_columns(), # type: ignore[attr-defined, ty:unresolved-attribute]
arg_state.action.get_table_columns(), # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
)

# Skip table generation if results are outside thresholds or no columns are defined
Expand Down Expand Up @@ -761,7 +761,7 @@ def _complete_arg(
:raises CompletionError: if the completer or choices function this calls raises one
"""
# Check if the argument uses a completer
completer = arg_state.action.get_completer() # type: ignore[attr-defined, ty:unresolved-attribute]
completer = arg_state.action.get_completer() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if completer is not None:
args, kwargs = self._prepare_callable_params(
completer,
Expand All @@ -775,7 +775,7 @@ def _complete_arg(

# Otherwise it uses a choices provider or choices list
else:
choices_provider = arg_state.action.get_choices_provider() # type: ignore[attr-defined, ty:unresolved-attribute]
choices_provider = arg_state.action.get_choices_provider() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if choices_provider is not None:
args, kwargs = self._prepare_callable_params(
choices_provider,
Expand Down
32 changes: 16 additions & 16 deletions cmd2/argparse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,11 @@ def _ActionsContainer_add_argument( # noqa: N802
new_arg = orig_actions_container_add_argument(self, *args, **kwargs)

# Set the cmd2-specific attributes
new_arg.set_nargs_range(nargs_range) # type: ignore[attr-defined, ty:unresolved-attribute]
new_arg.set_choices_provider(choices_provider) # type: ignore[attr-defined, ty:unresolved-attribute]
new_arg.set_completer(completer) # type: ignore[attr-defined, ty:unresolved-attribute]
new_arg.set_suppress_tab_hint(suppress_tab_hint) # type: ignore[attr-defined, ty:unresolved-attribute]
new_arg.set_table_columns(table_columns) # type: ignore[attr-defined, ty:unresolved-attribute]
new_arg.set_nargs_range(nargs_range) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
new_arg.set_choices_provider(choices_provider) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
new_arg.set_completer(completer) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
new_arg.set_suppress_tab_hint(suppress_tab_hint) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
new_arg.set_table_columns(table_columns) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]

# Set other registered custom attributes
for keyword, value in custom_attribs.items():
Expand Down Expand Up @@ -666,14 +666,14 @@ def _SubParsersAction_remove_all_parsers( # noqa: N802
# Get the next subcommand name. remove_parser() will remove
# it and any associated aliases from _name_parser_map.
name = next(iter(self._name_parser_map))
record = self.remove_parser(name) # type: ignore[attr-defined, ty:unresolved-attribute]
record = self.remove_parser(name) # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
records.append(record)

return records


argparse._SubParsersAction.remove_parser = _SubParsersAction_remove_parser # type: ignore[attr-defined, ty:unresolved-attribute]
argparse._SubParsersAction.remove_all_parsers = _SubParsersAction_remove_all_parsers # type: ignore[attr-defined, ty:unresolved-attribute]
argparse._SubParsersAction.remove_parser = _SubParsersAction_remove_parser # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
argparse._SubParsersAction.remove_all_parsers = _SubParsersAction_remove_all_parsers # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]


@dataclass
Expand Down Expand Up @@ -747,8 +747,8 @@ def __init__(
super().__init__(
prog=prog,
usage=usage,
description=description, # type: ignore[arg-type, ty:invalid-argument-type]
epilog=epilog, # type: ignore[arg-type, ty:invalid-argument-type]
description=description, # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
epilog=epilog, # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
parents=parents,
formatter_class=formatter_class,
prefix_chars=prefix_chars,
Expand All @@ -772,15 +772,15 @@ def __init__(
self.description: HelpContent | None # type: ignore[assignment]
self.epilog: HelpContent | None # type: ignore[assignment]

def print_usage(self, file: IO[str] | None = None) -> None: # type: ignore[override, ty:invalid-method-override]
def print_usage(self, file: IO[str] | None = None) -> None: # type: ignore[override] # ty: ignore[invalid-method-override]
"""Override to ensure the formatter is aware of the target file."""
if file is None:
file = self._thread_locals.current_output_file

with self.output_to(file):
super().print_usage(file)

def print_help(self, file: IO[str] | None = None) -> None: # type: ignore[override, ty:invalid-method-override]
def print_help(self, file: IO[str] | None = None) -> None: # type: ignore[override] # ty: ignore[invalid-method-override]
"""Override to ensure the formatter is aware of the target file."""
if file is None:
file = self._thread_locals.current_output_file
Expand Down Expand Up @@ -984,7 +984,7 @@ def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) ->
try:
record = cast(
SubcommandRecord,
subparsers_action.remove_parser(subcommand), # type: ignore[attr-defined, ty:unresolved-attribute]
subparsers_action.remove_parser(subcommand), # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
)
except ValueError:
raise ValueError(f"Subcommand '{subcommand}' does not exist for '{target_parser.prog}'") from None
Expand All @@ -1006,7 +1006,7 @@ def detach_all_subcommands(self, subcommand_path: Iterable[str]) -> list[Subcomm

records = cast(
list[SubcommandRecord],
subparsers_action.remove_all_parsers(), # type: ignore[attr-defined, ty:unresolved-attribute]
subparsers_action.remove_all_parsers(), # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
)
# Update command for each detached subcommand
for record in records:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def format_help(self, *args: Any, **kwargs: Any) -> str:

def _get_nargs_pattern(self, action: argparse.Action) -> str:
"""Override to support nargs ranges."""
nargs_range = action.get_nargs_range() # type: ignore[attr-defined, ty:unresolved-attribute]
nargs_range = action.get_nargs_range() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if nargs_range:
range_max = "" if nargs_range[1] == constants.INFINITY else nargs_range[1]
nargs_pattern = f"(-*A{{{nargs_range[0]},{range_max}}}-*)"
Expand All @@ -1066,7 +1066,7 @@ def _match_argument(self, action: argparse.Action, arg_strings_pattern: str) ->

# raise an exception if we weren't able to find a match
if match is None:
nargs_range = action.get_nargs_range() # type: ignore[attr-defined, ty:unresolved-attribute]
nargs_range = action.get_nargs_range() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
if nargs_range is not None:
raise ArgumentError(action, build_range_error(nargs_range[0], nargs_range[1]))

Expand Down
Loading
Loading