Skip to content

Commit d1de592

Browse files
committed
Merge branch 'main' into prompt-toolkit
2 parents e4136ae + d788902 commit d1de592

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
exclude: ^examples/transcripts/
1212

1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: "v0.14.14"
14+
rev: "v0.15.0"
1515
hooks:
1616
- id: ruff-format
1717
args: [--config=ruff.toml]
@@ -23,5 +23,5 @@ repos:
2323
hooks:
2424
- id: prettier
2525
additional_dependencies:
26-
- prettier@3.8.0
26+
- prettier@3.8.1
2727
- prettier-plugin-toml@2.0.6

cmd2/argparse_completer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def _complete_flags(
524524

525525
self._cmd2_app.display_matches.append(flag_text)
526526
# Use the first option string as the completion result for this action
527-
results.append(CompletionItem(option_strings[0], [action.help if action.help else '']))
527+
results.append(CompletionItem(option_strings[0], [action.help or '']))
528528
return results
529529

530530
def _format_completions(self, arg_state: _ArgumentState, completions: list[str] | list[CompletionItem]) -> list[str]:
@@ -556,7 +556,7 @@ def _format_completions(self, arg_state: _ArgumentState, completions: list[str]
556556
return cast(list[str], completions)
557557

558558
# If a metavar was defined, use that instead of the dest field
559-
destination = arg_state.action.metavar if arg_state.action.metavar else arg_state.action.dest
559+
destination = arg_state.action.metavar or arg_state.action.dest
560560

561561
# Handle case where metavar was a tuple
562562
if isinstance(destination, tuple):
@@ -653,7 +653,7 @@ def _complete_arg(
653653
for action in arg_state.action._choices_actions:
654654
if action.dest in arg_state.action.choices:
655655
subparser = arg_state.action.choices[action.dest]
656-
parser_help[subparser] = action.help if action.help else ''
656+
parser_help[subparser] = action.help or ''
657657
for name, subparser in arg_state.action.choices.items():
658658
items.append(CompletionItem(name, [parser_help.get(subparser, '')]))
659659
arg_choices = items

cmd2/argparse_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ def __init__(
14771477
usage=usage,
14781478
description=description, # type: ignore[arg-type]
14791479
epilog=epilog, # type: ignore[arg-type]
1480-
parents=parents if parents else [],
1480+
parents=parents or [],
14811481
formatter_class=formatter_class,
14821482
prefix_chars=prefix_chars,
14831483
fromfile_prefix_chars=fromfile_prefix_chars,

cmd2/cmd2.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,11 @@ def register_command_set(self, cmdset: CommandSet) -> None:
800800
list[tuple[str, Callable[..., Any]]],
801801
inspect.getmembers(
802802
cmdset,
803-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
804-
and hasattr(meth, '__name__')
805-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
803+
predicate=lambda meth: ( # type: ignore[arg-type]
804+
isinstance(meth, Callable) # type: ignore[arg-type]
805+
and hasattr(meth, '__name__')
806+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
807+
),
806808
),
807809
)
808810

@@ -955,9 +957,11 @@ def unregister_command_set(self, cmdset: CommandSet) -> None:
955957

956958
methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers(
957959
cmdset,
958-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
959-
and hasattr(meth, '__name__')
960-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
960+
predicate=lambda meth: ( # type: ignore[arg-type]
961+
isinstance(meth, Callable) # type: ignore[arg-type]
962+
and hasattr(meth, '__name__')
963+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
964+
),
961965
)
962966

963967
for cmd_func_name, command_method in methods:
@@ -1001,9 +1005,11 @@ def check_parser_uninstallable(parser: argparse.ArgumentParser) -> None:
10011005

10021006
methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers(
10031007
cmdset,
1004-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
1005-
and hasattr(meth, '__name__')
1006-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
1008+
predicate=lambda meth: ( # type: ignore[arg-type]
1009+
isinstance(meth, Callable) # type: ignore[arg-type]
1010+
and hasattr(meth, '__name__')
1011+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
1012+
),
10071013
)
10081014

10091015
for cmd_func_name, command_method in methods:
@@ -1025,10 +1031,12 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
10251031
# find methods that have the required attributes necessary to be recognized as a sub-command
10261032
methods = inspect.getmembers(
10271033
cmdset,
1028-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
1029-
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1030-
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1031-
and hasattr(meth, constants.CMD_ATTR_ARGPARSER),
1034+
predicate=lambda meth: (
1035+
isinstance(meth, Callable) # type: ignore[arg-type]
1036+
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1037+
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1038+
and hasattr(meth, constants.CMD_ATTR_ARGPARSER)
1039+
),
10321040
)
10331041

10341042
# iterate through all matching methods
@@ -1114,10 +1122,12 @@ def _unregister_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
11141122
# find methods that have the required attributes necessary to be recognized as a sub-command
11151123
methods = inspect.getmembers(
11161124
cmdset,
1117-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
1118-
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1119-
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1120-
and hasattr(meth, constants.CMD_ATTR_ARGPARSER),
1125+
predicate=lambda meth: (
1126+
isinstance(meth, Callable) # type: ignore[arg-type]
1127+
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1128+
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1129+
and hasattr(meth, constants.CMD_ATTR_ARGPARSER)
1130+
),
11211131
)
11221132

11231133
# iterate through all matching methods

cmd2/command_definition.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ def decorate_class(cls: CommandSetType) -> CommandSetType:
6363
# 3. Must be a member of the class being decorated and not one inherited from a parent declaration
6464
methods = inspect.getmembers(
6565
cls,
66-
predicate=lambda meth: inspect.isfunction(meth)
67-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
68-
and meth in inspect.getmro(cls)[0].__dict__.values(),
66+
predicate=lambda meth: (
67+
inspect.isfunction(meth)
68+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
69+
and meth in inspect.getmro(cls)[0].__dict__.values()
70+
),
6971
)
7072
category_decorator = with_category(category)
7173
for method in methods:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"devDependencies": {
3-
"prettier": "^3.8.0",
3+
"prettier": "^3.8.1",
44
"prettier-plugin-toml": "^2.0.6"
55
}
66
}

0 commit comments

Comments
 (0)