Skip to content

Commit 7bd62f6

Browse files
authored
Upgrade from ruff 0.12.9 to ruff 0.13.0 (#1508)
Most changes were done automatically by ruff. ruff is now stricter about prefacing unused variables with an underscore.
1 parent bf7152b commit 7bd62f6

14 files changed

+237
-237
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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.12.9"
12+
rev: "v0.13.0"
1313
hooks:
1414
- id: ruff-format
1515
args: [--config=pyproject.toml]

cmd2/cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6024,7 +6024,7 @@ def _validate_prepostcmd_hook(
60246024
type_hints, ret_ann = get_types(func)
60256025
if not type_hints:
60266026
raise TypeError(f"{func.__name__} parameter is missing a type hint, expected: {data_type}")
6027-
param_name, par_ann = next(iter(type_hints.items()))
6027+
_param_name, par_ann = next(iter(type_hints.items()))
60286028
# validate the parameter has the right annotation
60296029
if par_ann != data_type:
60306030
raise TypeError(f'argument 1 of {func.__name__} has incompatible type {par_ann}, expected {data_type}')

tests/test_argparse.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ def argparse_app():
126126

127127

128128
def test_invalid_syntax(argparse_app) -> None:
129-
out, err = run_cmd(argparse_app, 'speak "')
129+
_out, err = run_cmd(argparse_app, 'speak "')
130130
assert err[0] == "Invalid syntax: No closing quotation"
131131

132132

133133
def test_argparse_basic_command(argparse_app) -> None:
134-
out, err = run_cmd(argparse_app, 'say hello')
134+
out, _err = run_cmd(argparse_app, 'say hello')
135135
assert out == ['hello']
136136

137137

138138
def test_argparse_remove_quotes(argparse_app) -> None:
139-
out, err = run_cmd(argparse_app, 'say "hello there"')
139+
out, _err = run_cmd(argparse_app, 'say "hello there"')
140140
assert out == ['hello there']
141141

142142

@@ -150,64 +150,64 @@ def test_argparse_with_no_args(argparse_app) -> None:
150150
def test_argparser_kwargs(argparse_app, capsys) -> None:
151151
"""Test with_argparser wrapper passes through kwargs to command function"""
152152
argparse_app.do_say('word', keyword_arg="foo")
153-
out, err = capsys.readouterr()
153+
out, _err = capsys.readouterr()
154154
assert out == "foo\n"
155155

156156

157157
def test_argparse_preserve_quotes(argparse_app) -> None:
158-
out, err = run_cmd(argparse_app, 'tag mytag "hello"')
158+
out, _err = run_cmd(argparse_app, 'tag mytag "hello"')
159159
assert out[0] == '<mytag>"hello"</mytag>'
160160

161161

162162
def test_argparse_custom_namespace(argparse_app) -> None:
163-
out, err = run_cmd(argparse_app, 'test_argparse_ns')
163+
out, _err = run_cmd(argparse_app, 'test_argparse_ns')
164164
assert out[0] == 'custom'
165165

166166

167167
def test_argparse_with_list(argparse_app) -> None:
168-
out, err = run_cmd(argparse_app, 'speak -s hello world!')
168+
out, _err = run_cmd(argparse_app, 'speak -s hello world!')
169169
assert out == ['HELLO WORLD!']
170170

171171

172172
def test_argparse_with_list_remove_quotes(argparse_app) -> None:
173-
out, err = run_cmd(argparse_app, 'speak -s hello "world!"')
173+
out, _err = run_cmd(argparse_app, 'speak -s hello "world!"')
174174
assert out == ['HELLO WORLD!']
175175

176176

177177
def test_argparse_with_list_preserve_quotes(argparse_app) -> None:
178-
out, err = run_cmd(argparse_app, 'test_argparse_with_list_quotes "hello" person')
178+
out, _err = run_cmd(argparse_app, 'test_argparse_with_list_quotes "hello" person')
179179
assert out[0] == '"hello" person'
180180

181181

182182
def test_argparse_with_list_custom_namespace(argparse_app) -> None:
183-
out, err = run_cmd(argparse_app, 'test_argparse_with_list_ns')
183+
out, _err = run_cmd(argparse_app, 'test_argparse_with_list_ns')
184184
assert out[0] == 'custom'
185185

186186

187187
def test_argparse_with_list_and_empty_doc(argparse_app) -> None:
188-
out, err = run_cmd(argparse_app, 'speak -s hello world!')
188+
out, _err = run_cmd(argparse_app, 'speak -s hello world!')
189189
assert out == ['HELLO WORLD!']
190190

191191

192192
def test_argparser_correct_args_with_quotes_and_midline_options(argparse_app) -> None:
193-
out, err = run_cmd(argparse_app, "speak 'This is a' -s test of the emergency broadcast system!")
193+
out, _err = run_cmd(argparse_app, "speak 'This is a' -s test of the emergency broadcast system!")
194194
assert out == ['THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM!']
195195

196196

197197
def test_argparser_and_unknown_args_kwargs(argparse_app, capsys) -> None:
198198
"""Test with_argparser wrapper passing through kwargs to command function"""
199199
argparse_app.do_speak('', keyword_arg="foo")
200-
out, err = capsys.readouterr()
200+
out, _err = capsys.readouterr()
201201
assert out == "foo\n"
202202

203203

204204
def test_argparse_quoted_arguments_multiple(argparse_app) -> None:
205-
out, err = run_cmd(argparse_app, 'say "hello there" "rick & morty"')
205+
out, _err = run_cmd(argparse_app, 'say "hello there" "rick & morty"')
206206
assert out == ['hello there rick & morty']
207207

208208

209209
def test_argparse_help_docstring(argparse_app) -> None:
210-
out, err = run_cmd(argparse_app, 'help say')
210+
out, _err = run_cmd(argparse_app, 'help say')
211211
assert out[0].startswith('Usage: say')
212212
assert out[1] == ''
213213
assert out[2] == 'Repeat what you tell me to.'
@@ -216,32 +216,32 @@ def test_argparse_help_docstring(argparse_app) -> None:
216216

217217

218218
def test_argparse_help_description(argparse_app) -> None:
219-
out, err = run_cmd(argparse_app, 'help tag')
219+
out, _err = run_cmd(argparse_app, 'help tag')
220220
assert out[0].startswith('Usage: tag')
221221
assert out[1] == ''
222222
assert out[2] == 'create a html tag'
223223

224224

225225
def test_argparse_prog(argparse_app) -> None:
226-
out, err = run_cmd(argparse_app, 'help tag')
226+
out, _err = run_cmd(argparse_app, 'help tag')
227227
progname = out[0].split(' ')[1]
228228
assert progname == 'tag'
229229

230230

231231
def test_arglist(argparse_app) -> None:
232-
out, err = run_cmd(argparse_app, 'arglist "we should" get these')
232+
out, _err = run_cmd(argparse_app, 'arglist "we should" get these')
233233
assert out[0] == 'True'
234234

235235

236236
def test_arglist_kwargs(argparse_app, capsys) -> None:
237237
"""Test with_argument_list wrapper passes through kwargs to command function"""
238238
argparse_app.do_arglist('arg', keyword_arg="foo")
239-
out, err = capsys.readouterr()
239+
out, _err = capsys.readouterr()
240240
assert out == "foo\n"
241241

242242

243243
def test_preservelist(argparse_app) -> None:
244-
out, err = run_cmd(argparse_app, 'preservelist foo "bar baz"')
244+
out, _err = run_cmd(argparse_app, 'preservelist foo "bar baz"')
245245
assert out[0] == "['foo', '\"bar baz\"']"
246246

247247

@@ -332,70 +332,70 @@ def subcommand_app():
332332

333333

334334
def test_subcommand_foo(subcommand_app) -> None:
335-
out, err = run_cmd(subcommand_app, 'base foo -x2 5.0')
335+
out, _err = run_cmd(subcommand_app, 'base foo -x2 5.0')
336336
assert out == ['10.0']
337337

338338

339339
def test_subcommand_bar(subcommand_app) -> None:
340-
out, err = run_cmd(subcommand_app, 'base bar baz')
340+
out, _err = run_cmd(subcommand_app, 'base bar baz')
341341
assert out == ['((baz))']
342342

343343

344344
def test_subcommand_invalid(subcommand_app) -> None:
345-
out, err = run_cmd(subcommand_app, 'base baz')
345+
_out, err = run_cmd(subcommand_app, 'base baz')
346346
assert err[0].startswith('Usage: base')
347347
assert err[1].startswith("Error: argument SUBCOMMAND: invalid choice: 'baz'")
348348

349349

350350
def test_subcommand_base_help(subcommand_app) -> None:
351-
out, err = run_cmd(subcommand_app, 'help base')
351+
out, _err = run_cmd(subcommand_app, 'help base')
352352
assert out[0].startswith('Usage: base')
353353
assert out[1] == ''
354354
assert out[2] == 'Base command help'
355355

356356

357357
def test_subcommand_help(subcommand_app) -> None:
358358
# foo has no aliases
359-
out, err = run_cmd(subcommand_app, 'help base foo')
359+
out, _err = run_cmd(subcommand_app, 'help base foo')
360360
assert out[0].startswith('Usage: base foo')
361361
assert out[1] == ''
362362
assert out[2] == 'Positional Arguments:'
363363

364364
# bar has aliases (usage should never show alias name)
365-
out, err = run_cmd(subcommand_app, 'help base bar')
365+
out, _err = run_cmd(subcommand_app, 'help base bar')
366366
assert out[0].startswith('Usage: base bar')
367367
assert out[1] == ''
368368
assert out[2] == 'Positional Arguments:'
369369

370-
out, err = run_cmd(subcommand_app, 'help base bar_1')
370+
out, _err = run_cmd(subcommand_app, 'help base bar_1')
371371
assert out[0].startswith('Usage: base bar')
372372
assert out[1] == ''
373373
assert out[2] == 'Positional Arguments:'
374374

375-
out, err = run_cmd(subcommand_app, 'help base bar_2')
375+
out, _err = run_cmd(subcommand_app, 'help base bar_2')
376376
assert out[0].startswith('Usage: base bar')
377377
assert out[1] == ''
378378
assert out[2] == 'Positional Arguments:'
379379

380380
# helpless has aliases and no help text (usage should never show alias name)
381-
out, err = run_cmd(subcommand_app, 'help base helpless')
381+
out, _err = run_cmd(subcommand_app, 'help base helpless')
382382
assert out[0].startswith('Usage: base helpless')
383383
assert out[1] == ''
384384
assert out[2] == 'Positional Arguments:'
385385

386-
out, err = run_cmd(subcommand_app, 'help base helpless_1')
386+
out, _err = run_cmd(subcommand_app, 'help base helpless_1')
387387
assert out[0].startswith('Usage: base helpless')
388388
assert out[1] == ''
389389
assert out[2] == 'Positional Arguments:'
390390

391-
out, err = run_cmd(subcommand_app, 'help base helpless_2')
391+
out, _err = run_cmd(subcommand_app, 'help base helpless_2')
392392
assert out[0].startswith('Usage: base helpless')
393393
assert out[1] == ''
394394
assert out[2] == 'Positional Arguments:'
395395

396396

397397
def test_subcommand_invalid_help(subcommand_app) -> None:
398-
out, err = run_cmd(subcommand_app, 'help base baz')
398+
out, _err = run_cmd(subcommand_app, 'help base baz')
399399
assert out[0].startswith('Usage: base')
400400

401401

tests/test_argparse_completer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,16 @@ def ac_app():
348348

349349
@pytest.mark.parametrize('command', ['music', 'music create', 'music create rock', 'music create jazz'])
350350
def test_help(ac_app, command) -> None:
351-
out1, err1 = run_cmd(ac_app, f'{command} -h')
352-
out2, err2 = run_cmd(ac_app, f'help {command}')
351+
out1, _err1 = run_cmd(ac_app, f'{command} -h')
352+
out2, _err2 = run_cmd(ac_app, f'help {command}')
353353
assert out1 == out2
354354

355355

356356
def test_bad_subcommand_help(ac_app) -> None:
357357
# These should give the same output because the second one isn't using a
358358
# real subcommand, so help will be called on the music command instead.
359-
out1, err1 = run_cmd(ac_app, 'help music')
360-
out2, err2 = run_cmd(ac_app, 'help music fake')
359+
out1, _err1 = run_cmd(ac_app, 'help music')
360+
out2, _err2 = run_cmd(ac_app, 'help music fake')
361361
assert out1 == out2
362362

363363

@@ -907,7 +907,7 @@ def test_unfinished_flag_error(ac_app, command_and_args, text, is_error, capsys)
907907

908908
complete_tester(text, line, begidx, endidx, ac_app)
909909

910-
out, err = capsys.readouterr()
910+
out, _err = capsys.readouterr()
911911
assert is_error == all(x in out for x in ["Error: argument", "expected"])
912912

913913

@@ -1016,7 +1016,7 @@ def test_autocomp_hint(ac_app, command_and_args, text, has_hint, capsys) -> None
10161016
begidx = endidx - len(text)
10171017

10181018
complete_tester(text, line, begidx, endidx, ac_app)
1019-
out, err = capsys.readouterr()
1019+
out, _err = capsys.readouterr()
10201020
if has_hint:
10211021
assert "Hint:\n" in out
10221022
else:
@@ -1030,7 +1030,7 @@ def test_autocomp_hint_no_help_text(ac_app, capsys) -> None:
10301030
begidx = endidx - len(text)
10311031

10321032
first_match = complete_tester(text, line, begidx, endidx, ac_app)
1033-
out, err = capsys.readouterr()
1033+
out, _err = capsys.readouterr()
10341034

10351035
assert first_match is None
10361036
assert out != '''\nHint:\n NO_HELP_POS\n\n'''
@@ -1051,7 +1051,7 @@ def test_completion_error(ac_app, capsys, args, text) -> None:
10511051
begidx = endidx - len(text)
10521052

10531053
first_match = complete_tester(text, line, begidx, endidx, ac_app)
1054-
out, err = capsys.readouterr()
1054+
out, _err = capsys.readouterr()
10551055

10561056
assert first_match is None
10571057
assert f"{text} broke something" in out
@@ -1113,7 +1113,7 @@ def test_complete_mutex_group(ac_app, command_and_args, text, output_contains, f
11131113

11141114
assert first_match == complete_tester(text, line, begidx, endidx, ac_app)
11151115

1116-
out, err = capsys.readouterr()
1116+
out, _err = capsys.readouterr()
11171117
assert output_contains in out
11181118

11191119

tests/test_argparse_custom.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,30 @@ def test_apcustom_usage() -> None:
8787

8888

8989
def test_apcustom_nargs_help_format(cust_app) -> None:
90-
out, err = run_cmd(cust_app, 'help range')
90+
out, _err = run_cmd(cust_app, 'help range')
9191
assert 'Usage: range [-h] [--arg0 ARG0] [--arg1 ARG1{2}] [--arg2 ARG2{3+}]' in out[0]
9292
assert ' [--arg3 ARG3{2..3}] [--arg4 [ARG4 [...]]] [--arg5 ARG5 [...]]' in out[1]
9393

9494

9595
def test_apcustom_nargs_range_validation(cust_app) -> None:
9696
# nargs = (3,) # noqa: ERA001
97-
out, err = run_cmd(cust_app, 'range --arg2 one two')
97+
_out, err = run_cmd(cust_app, 'range --arg2 one two')
9898
assert 'Error: argument --arg2: expected at least 3 arguments' in err[2]
9999

100-
out, err = run_cmd(cust_app, 'range --arg2 one two three')
100+
_out, err = run_cmd(cust_app, 'range --arg2 one two three')
101101
assert not err
102102

103-
out, err = run_cmd(cust_app, 'range --arg2 one two three four')
103+
_out, err = run_cmd(cust_app, 'range --arg2 one two three four')
104104
assert not err
105105

106106
# nargs = (2,3) # noqa: ERA001
107-
out, err = run_cmd(cust_app, 'range --arg3 one')
107+
_out, err = run_cmd(cust_app, 'range --arg3 one')
108108
assert 'Error: argument --arg3: expected 2 to 3 arguments' in err[2]
109109

110-
out, err = run_cmd(cust_app, 'range --arg3 one two')
110+
_out, err = run_cmd(cust_app, 'range --arg3 one two')
111111
assert not err
112112

113-
out, err = run_cmd(cust_app, 'range --arg2 one two three')
113+
_out, err = run_cmd(cust_app, 'range --arg2 one two three')
114114
assert not err
115115

116116

@@ -284,7 +284,7 @@ def test_completion_items_as_choices(capsys) -> None:
284284
args = parser.parse_args(['3'])
285285

286286
# Confirm error text contains correct value type of str
287-
out, err = capsys.readouterr()
287+
_out, err = capsys.readouterr()
288288
assert "invalid choice: '3' (choose from '1', '2')" in err
289289

290290
##############################################################
@@ -306,5 +306,5 @@ def test_completion_items_as_choices(capsys) -> None:
306306
args = parser.parse_args(['3'])
307307

308308
# Confirm error text contains correct value type of int
309-
out, err = capsys.readouterr()
309+
_out, err = capsys.readouterr()
310310
assert 'invalid choice: 3 (choose from 1, 2)' in err

0 commit comments

Comments
 (0)