Skip to content

Commit d788902

Browse files
committed
Upgrae to ruff 0.15.0 and prettier 3.8.1
Ruff changed 2 relevant things: - Sometimes prefers to use or instead of if in assignment - Improved Lambda function formatting
1 parent 48bfc0d commit d788902

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: trailing-whitespace
1010

1111
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: "v0.14.14"
12+
rev: "v0.15.0"
1313
hooks:
1414
- id: ruff-format
1515
args: [--config=ruff.toml]
@@ -21,5 +21,5 @@ repos:
2121
hooks:
2222
- id: prettier
2323
additional_dependencies:
24-
- prettier@3.8.0
24+
- prettier@3.8.1
2525
- prettier-plugin-toml@2.0.6

cmd2/argparse_completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def _format_completions(self, arg_state: _ArgumentState, completions: list[str]
539539
# Check if there are too many CompletionItems to display as a table
540540
if len(completions) <= self._cmd2_app.max_completion_items:
541541
# If a metavar was defined, use that instead of the dest field
542-
destination = arg_state.action.metavar if arg_state.action.metavar else arg_state.action.dest
542+
destination = arg_state.action.metavar or arg_state.action.dest
543543

544544
# Handle case where metavar was a tuple
545545
if isinstance(destination, tuple):

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: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,11 @@ def register_command_set(self, cmdset: CommandSet) -> None:
758758
list[tuple[str, Callable[..., Any]]],
759759
inspect.getmembers(
760760
cmdset,
761-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
762-
and hasattr(meth, '__name__')
763-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
761+
predicate=lambda meth: ( # type: ignore[arg-type]
762+
isinstance(meth, Callable) # type: ignore[arg-type]
763+
and hasattr(meth, '__name__')
764+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
765+
),
764766
),
765767
)
766768

@@ -913,9 +915,11 @@ def unregister_command_set(self, cmdset: CommandSet) -> None:
913915

914916
methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers(
915917
cmdset,
916-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
917-
and hasattr(meth, '__name__')
918-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
918+
predicate=lambda meth: ( # type: ignore[arg-type]
919+
isinstance(meth, Callable) # type: ignore[arg-type]
920+
and hasattr(meth, '__name__')
921+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
922+
),
919923
)
920924

921925
for cmd_func_name, command_method in methods:
@@ -959,9 +963,11 @@ def check_parser_uninstallable(parser: argparse.ArgumentParser) -> None:
959963

960964
methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers(
961965
cmdset,
962-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
963-
and hasattr(meth, '__name__')
964-
and meth.__name__.startswith(COMMAND_FUNC_PREFIX),
966+
predicate=lambda meth: ( # type: ignore[arg-type]
967+
isinstance(meth, Callable) # type: ignore[arg-type]
968+
and hasattr(meth, '__name__')
969+
and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
970+
),
965971
)
966972

967973
for cmd_func_name, command_method in methods:
@@ -983,10 +989,12 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
983989
# find methods that have the required attributes necessary to be recognized as a sub-command
984990
methods = inspect.getmembers(
985991
cmdset,
986-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
987-
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
988-
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
989-
and hasattr(meth, constants.CMD_ATTR_ARGPARSER),
992+
predicate=lambda meth: (
993+
isinstance(meth, Callable) # type: ignore[arg-type]
994+
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
995+
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
996+
and hasattr(meth, constants.CMD_ATTR_ARGPARSER)
997+
),
990998
)
991999

9921000
# iterate through all matching methods
@@ -1072,10 +1080,12 @@ def _unregister_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
10721080
# find methods that have the required attributes necessary to be recognized as a sub-command
10731081
methods = inspect.getmembers(
10741082
cmdset,
1075-
predicate=lambda meth: isinstance(meth, Callable) # type: ignore[arg-type]
1076-
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1077-
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1078-
and hasattr(meth, constants.CMD_ATTR_ARGPARSER),
1083+
predicate=lambda meth: (
1084+
isinstance(meth, Callable) # type: ignore[arg-type]
1085+
and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1086+
and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1087+
and hasattr(meth, constants.CMD_ATTR_ARGPARSER)
1088+
),
10791089
)
10801090

10811091
# iterate through all matching methods
@@ -2262,7 +2272,7 @@ def _display_matches_pyreadline(self, matches: list[str]) -> None: # pragma: no
22622272
# Otherwise use pyreadline3's formatter
22632273
else:
22642274
# Check if we should show display_matches
2265-
matches_to_display = self.display_matches if self.display_matches else matches
2275+
matches_to_display = self.display_matches or matches
22662276

22672277
# Add padding for visual appeal
22682278
matches_to_display, _ = self._pad_matches_to_display(matches_to_display)

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)