Skip to content

Commit 29e64d6

Browse files
committed
Enable ruff RET ruleset
1 parent 2dd2909 commit 29e64d6

15 files changed

+33
-66
lines changed

cmd2/clipboard.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ def get_paste_buffer() -> str:
1010
1111
:return: contents of the clipboard
1212
"""
13-
pb_str = typing.cast(str, pyperclip.paste())
14-
return pb_str
13+
return typing.cast(str, pyperclip.paste())
1514

1615

1716
def write_to_paste_buffer(txt: str) -> None:

cmd2/parsing.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ def __new__(cls, value: object, *pos_args: Any, **kw_args: Any) -> 'Statement':
154154
NOTE: @dataclass takes care of initializing other members in the __init__ it
155155
generates.
156156
"""
157-
stmt = super().__new__(cls, value)
158-
return stmt
157+
return super().__new__(cls, value)
159158

160159
@property
161160
def command_and_args(self) -> str:
@@ -382,8 +381,7 @@ def tokenize(self, line: str) -> list[str]:
382381
raise Cmd2ShlexError(ex)
383382

384383
# custom lexing
385-
tokens = self.split_on_punctuation(tokens)
386-
return tokens
384+
return self.split_on_punctuation(tokens)
387385

388386
def parse(self, line: str) -> Statement:
389387
"""Tokenize the input and parse it into a [cmd2.parsing.Statement][] object,
@@ -515,7 +513,7 @@ def parse(self, line: str) -> Statement:
515513
multiline_command = ''
516514

517515
# build the statement
518-
statement = Statement(
516+
return Statement(
519517
args,
520518
raw=line,
521519
command=command,
@@ -527,7 +525,6 @@ def parse(self, line: str) -> Statement:
527525
output=output,
528526
output_to=output_to,
529527
)
530-
return statement
531528

532529
def parse_command_only(self, rawinput: str) -> Statement:
533530
"""Partially parse input into a [cmd2.Statement][] object.
@@ -589,8 +586,7 @@ def parse_command_only(self, rawinput: str) -> Statement:
589586
multiline_command = ''
590587

591588
# build the statement
592-
statement = Statement(args, raw=rawinput, command=command, multiline_command=multiline_command)
593-
return statement
589+
return Statement(args, raw=rawinput, command=command, multiline_command=multiline_command)
594590

595591
def get_command_arg_list(
596592
self, command_name: str, to_parse: Union[Statement, str], preserve_quotes: bool

cmd2/py_bridge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ def __call__(self, command: str, *, echo: Optional[bool] = None) -> CommandResul
137137
self.stop = stop or self.stop
138138

139139
# Save the result
140-
result = CommandResult(
140+
return CommandResult(
141141
stdout=copy_cmd_stdout.getvalue(),
142142
stderr=copy_stderr.getvalue(),
143143
stop=stop,
144144
data=self._cmd2_app.last_result,
145145
)
146-
return result

plugins/template/tests/test_myplugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def do_empty(self, args) -> None:
3535

3636

3737
def init_app():
38-
app = MyApp()
39-
return app
38+
return MyApp()
4039

4140

4241
#####

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ select = [
203203
# "PTH", # flake8-use-pathlib (force use of pathlib instead of os.path)
204204
"PYI", # flake8-pyi (warnings related to type hint best practices)
205205
"Q", # flake8-quotes (force double quotes)
206-
# "RET", # flake8-return (various warnings related to implicit vs explicit return statements)
206+
"RET", # flake8-return (various warnings related to implicit vs explicit return statements)
207207
"RSE", # flake8-raise (warn about unnecessary parentheses on raised exceptions)
208208
# "RUF", # Ruff-specific rules (miscellaneous grab bag of lint checks specific to Ruff)
209209
# "S", # flake8-bandit (security oriented checks, but extremely pedantic - do not attempt to apply to unit test files)

tests/test_argparse.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ def do_test_argparse_with_list_ns(self, args, extra) -> None:
122122

123123
@pytest.fixture
124124
def argparse_app():
125-
app = ArgparseApp()
126-
return app
125+
return ArgparseApp()
127126

128127

129128
def test_invalid_syntax(argparse_app) -> None:
@@ -324,8 +323,7 @@ def helpless_subcmd_func(self, args: argparse.Namespace) -> None:
324323

325324
@pytest.fixture
326325
def subcommand_app():
327-
app = SubcommandApp()
328-
return app
326+
return SubcommandApp()
329327

330328

331329
def test_subcommand_foo(subcommand_app) -> None:

tests/test_argparse_completer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,8 +1268,7 @@ def _subcmd_custom(self, args: argparse.Namespace) -> None:
12681268

12691269
@pytest.fixture
12701270
def custom_completer_app():
1271-
app = CustomCompleterApp()
1272-
return app
1271+
return CustomCompleterApp()
12731272

12741273

12751274
def test_default_custom_completer_type(custom_completer_app: CustomCompleterApp) -> None:

tests/test_cmd2.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ def _onchange_quiet(self, name, old, new) -> None:
280280

281281
@pytest.fixture
282282
def onchange_app():
283-
app = OnChangeHookApp()
284-
return app
283+
return OnChangeHookApp()
285284

286285

287286
def test_set_onchange_hook(onchange_app) -> None:
@@ -847,15 +846,13 @@ def _expected_no_editor_error():
847846
if hasattr(sys, "pypy_translation_info"):
848847
expected_exception = 'EnvironmentError'
849848

850-
expected_text = normalize(
849+
return normalize(
851850
f"""
852851
EXCEPTION of type '{expected_exception}' occurred with message: Please use 'set editor' to specify your text editing program of choice.
853852
To enable full traceback, run the following command: 'set debug true'
854853
"""
855854
)
856855

857-
return expected_text
858-
859856

860857
def test_base_debug(base_app) -> None:
861858
# Purposely set the editor to None
@@ -1086,8 +1083,7 @@ def postparsing_precmd(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.P
10861083

10871084
@pytest.fixture
10881085
def hook_failure():
1089-
app = HookFailureApp()
1090-
return app
1086+
return HookFailureApp()
10911087

10921088

10931089
def test_precmd_hook_success(base_app) -> None:
@@ -1211,8 +1207,7 @@ def do_parser_cmd(self, args) -> None:
12111207

12121208
@pytest.fixture
12131209
def help_app():
1214-
app = HelpApp()
1215-
return app
1210+
return HelpApp()
12161211

12171212

12181213
def test_custom_command_help(help_app) -> None:
@@ -1285,8 +1280,7 @@ def do_undoc(self, arg) -> None:
12851280

12861281
@pytest.fixture
12871282
def helpcat_app():
1288-
app = HelpCategoriesApp()
1289-
return app
1283+
return HelpCategoriesApp()
12901284

12911285

12921286
def test_help_cat_base(helpcat_app) -> None:
@@ -1342,8 +1336,7 @@ def do_return_type(self, arg) -> None:
13421336

13431337
@pytest.fixture
13441338
def select_app():
1345-
app = SelectApp()
1346-
return app
1339+
return SelectApp()
13471340

13481341

13491342
def test_select_options(select_app, monkeypatch) -> None:
@@ -1592,8 +1585,7 @@ def do_orate(self, opts, arg) -> None:
15921585

15931586
@pytest.fixture
15941587
def multiline_app():
1595-
app = MultilineApp()
1596-
return app
1588+
return MultilineApp()
15971589

15981590

15991591
def test_multiline_complete_empty_statement_raises_exception(multiline_app) -> None:
@@ -1759,8 +1751,7 @@ def do_negative_no_data(self, arg) -> None:
17591751

17601752
@pytest.fixture
17611753
def commandresult_app():
1762-
app = CommandResultApp()
1763-
return app
1754+
return CommandResultApp()
17641755

17651756

17661757
def test_commandresult_truthy(commandresult_app) -> None:
@@ -2813,8 +2804,7 @@ def do_has_no_helper_funcs(self, arg) -> None:
28132804

28142805
@pytest.fixture
28152806
def disable_commands_app():
2816-
app = DisableCommandsApp()
2817-
return app
2807+
return DisableCommandsApp()
28182808

28192809

28202810
def test_disable_and_enable_category(disable_commands_app) -> None:

tests/test_completion.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ def completedefault(self, *ignored):
122122

123123
@pytest.fixture
124124
def cmd2_app():
125-
c = CompletionsExample()
126-
return c
125+
return CompletionsExample()
127126

128127

129128
def test_cmd2_command_completion_single(cmd2_app) -> None:
@@ -1261,8 +1260,7 @@ def do_base(self, args) -> None:
12611260
@pytest.fixture
12621261
def scu_app():
12631262
"""Declare test fixture for with_argparser decorator"""
1264-
app = SubcommandsWithUnknownExample()
1265-
return app
1263+
return SubcommandsWithUnknownExample()
12661264

12671265

12681266
def test_subcmd_with_unknown_completion_single_end(scu_app) -> None:

tests/test_history.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ def hist():
5656
Statement,
5757
)
5858

59-
h = History(
59+
return History(
6060
[
6161
HistoryItem(Statement('', raw='first')),
6262
HistoryItem(Statement('', raw='second')),
6363
HistoryItem(Statement('', raw='third')),
6464
HistoryItem(Statement('', raw='fourth')),
6565
]
6666
)
67-
return h
6867

6968

7069
# Represents the hist fixture's JSON
@@ -381,8 +380,7 @@ def histitem():
381380
command='help',
382381
arg_list=['history'],
383382
)
384-
histitem = HistoryItem(statement)
385-
return histitem
383+
return HistoryItem(statement)
386384

387385

388386
@pytest.fixture
@@ -391,7 +389,7 @@ def parser():
391389
StatementParser,
392390
)
393391

394-
parser = StatementParser(
392+
return StatementParser(
395393
terminators=[';', '&'],
396394
multiline_commands=['multiline'],
397395
aliases={
@@ -403,7 +401,6 @@ def parser():
403401
},
404402
shortcuts={'?': 'help', '!': 'shell'},
405403
)
406-
return parser
407404

408405

409406
def test_multiline_histitem(parser) -> None:

tests/test_parsing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@pytest.fixture
2121
def parser():
22-
parser = StatementParser(
22+
return StatementParser(
2323
terminators=[';', '&'],
2424
multiline_commands=['multiline'],
2525
aliases={
@@ -31,13 +31,11 @@ def parser():
3131
},
3232
shortcuts={'?': 'help', '!': 'shell'},
3333
)
34-
return parser
3534

3635

3736
@pytest.fixture
3837
def default_parser():
39-
parser = StatementParser()
40-
return parser
38+
return StatementParser()
4139

4240

4341
def test_parse_empty_string(parser) -> None:

tests/test_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def test_quote_string_if_needed_no() -> None:
142142

143143
@pytest.fixture
144144
def stdout_sim():
145-
stdsim = cu.StdSim(sys.stdout, echo=True)
146-
return stdsim
145+
return cu.StdSim(sys.stdout, echo=True)
147146

148147

149148
def test_stdsim_write_str(stdout_sim) -> None:
@@ -279,8 +278,7 @@ def pr_none():
279278
kwargs['start_new_session'] = True
280279

281280
proc = subprocess.Popen(command, shell=True, **kwargs)
282-
pr = cu.ProcReader(proc, None, None)
283-
return pr
281+
return cu.ProcReader(proc, None, None)
284282

285283

286284
def test_proc_reader_send_sigint(pr_none) -> None:

tests_isolated/test_commandset/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,9 @@ def __init__(self, *args, **kwargs) -> None:
180180

181181
@pytest.fixture
182182
def command_sets_app():
183-
app = WithCommandSets()
184-
return app
183+
return WithCommandSets()
185184

186185

187186
@pytest.fixture
188187
def command_sets_manual():
189-
app = WithCommandSets(auto_load_commands=False)
190-
return app
188+
return WithCommandSets(auto_load_commands=False)

tests_isolated/test_commandset/test_argparse_subcommands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def do_base(self, args) -> None:
6262

6363
@pytest.fixture
6464
def subcommand_app():
65-
app = WithCommandSets(auto_load_commands=False, command_sets=[SubcommandSet(1)])
66-
return app
65+
return WithCommandSets(auto_load_commands=False, command_sets=[SubcommandSet(1)])
6766

6867

6968
def test_subcommand_foo(subcommand_app) -> None:

tests_isolated/test_commandset/test_commandset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ def cut_bokchoy(self, _: argparse.Namespace) -> None:
748748

749749
@pytest.fixture
750750
def static_subcommands_app():
751-
app = AppWithSubCommands()
752-
return app
751+
return AppWithSubCommands()
753752

754753

755754
def test_static_subcommands(static_subcommands_app) -> None:

0 commit comments

Comments
 (0)