Skip to content

Commit 191c5e6

Browse files
committed
Minor edits to satisfy ruff format and check and mypy (latest versions)
1 parent dd9f134 commit 191c5e6

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

sphinxarg/ext.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import shutil
77
import sys
88
from argparse import ArgumentParser
9-
from typing import TYPE_CHECKING, cast
9+
from typing import TYPE_CHECKING, ClassVar, cast
1010

1111
from docutils import nodes
1212
from docutils.frontend import get_default_settings
@@ -179,7 +179,7 @@ def print_action_groups(
179179
arg = []
180180
if 'choices' in entry:
181181
arg.append(
182-
f"Possible choices: {', '.join(str(c) for c in entry['choices'])}\n"
182+
f'Possible choices: {", ".join(str(c) for c in entry["choices"])}\n'
183183
)
184184
if 'help' in entry:
185185
arg.append(entry['help'])
@@ -524,7 +524,7 @@ def _print_subcommands(self, data, nested_content, markdown_help=False, settings
524524
definitions = map_nested_definitions(nested_content)
525525
items = []
526526
full_subcommand_name_true = self.config.sphinxarg_full_subcommand_name
527-
domain = cast(ArgParseDomain, self.env.domains[ArgParseDomain.name])
527+
domain = cast('ArgParseDomain', self.env.domains[ArgParseDomain.name])
528528

529529
if 'children' in data:
530530
full_command = command_pos_args(data)
@@ -667,7 +667,7 @@ def _print_action_groups(
667667
arg = []
668668
if 'choices' in entry:
669669
arg.append(
670-
f"Possible choices: {', '.join(map(str, entry['choices']))}\n"
670+
f'Possible choices: {", ".join(map(str, entry["choices"]))}\n'
671671
)
672672
if 'help' in entry:
673673
arg.append(entry['help'])
@@ -814,7 +814,7 @@ def run(self):
814814
self.set_source_info(target)
815815
self.state.document.note_explicit_target(target)
816816

817-
domain = cast(ArgParseDomain, self.env.get_domain(ArgParseDomain.name))
817+
domain = cast('ArgParseDomain', self.env.get_domain(ArgParseDomain.name))
818818
domain.add_argparse_command(result, node_id, self.index_groups)
819819

820820
items.append(nodes.literal_block(text=result['usage']))
@@ -888,8 +888,8 @@ class ArgParseDomain(Domain):
888888
'command': XRefRole(),
889889
}
890890
indices = []
891-
initial_data: dict[
892-
str, list[_ObjectDescriptionTuple] | dict[str, list[_ObjectDescriptionTuple]]
891+
initial_data: ClassVar[
892+
dict[str, list[_ObjectDescriptionTuple] | dict[str, list[_ObjectDescriptionTuple]]]
893893
] = {
894894
'commands': [],
895895
'commands-by-group': {},
@@ -948,7 +948,7 @@ def add_argparse_command(self, result: dict, anchor: str, groups: Sequence[str]
948948

949949
def _delete_temporary_files(app: Sphinx, _err) -> None:
950950
assert app.env is not None
951-
domain = cast(ArgParseDomain, app.env.domains[ArgParseDomain.name])
951+
domain = cast('ArgParseDomain', app.env.domains[ArgParseDomain.name])
952952
for fpath in domain.temporary_index_files:
953953
fpath.unlink(missing_ok=True)
954954

@@ -973,12 +973,12 @@ def _create_temporary_dummy_file(
973973
f'Creating this temporary file enables you to add {docname} to the toctree.',
974974
))
975975
dummy_file.write_text(content, encoding='utf-8')
976-
domain = cast(ArgParseDomain, domain)
976+
domain = cast('ArgParseDomain', domain)
977977
domain.temporary_index_files.append(dummy_file)
978978

979979

980980
def configure_ext(app: Sphinx) -> None:
981-
domain = cast(ArgParseDomain, app.env.domains[ArgParseDomain.name])
981+
domain = cast('ArgParseDomain', app.env.domains[ArgParseDomain.name])
982982
build_index = False
983983
build_by_group_index = False
984984

sphinxarg/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parser_navigate(parser_result, path, current_path=None):
1818
if len(path) == 0:
1919
return parser_result
2020
if 'children' not in parser_result:
21-
msg = f"Current parser has no child elements. (path: {' '.join(current_path)})"
21+
msg = f'Current parser has no child elements. (path: {" ".join(current_path)})'
2222
raise NavigationException(msg)
2323
next_hop = path.pop(0)
2424
for child in parser_result['children']:
@@ -28,8 +28,8 @@ def parser_navigate(parser_result, path, current_path=None):
2828
current_path.append(next_hop)
2929
return parser_navigate(child, path, current_path)
3030
msg = (
31-
f"Current parser has no child element with name: {next_hop} "
32-
f"(path: {' '.join(current_path)})"
31+
f'Current parser has no child element with name: {next_hop} '
32+
f'(path: {" ".join(current_path)})'
3333
)
3434
raise NavigationException(msg)
3535

@@ -88,7 +88,7 @@ def parse_parser(parser, data=None, **kwargs):
8888
subalias = subsection_alias[subaction]
8989
subaction.prog = f'{parser.prog} {name}'
9090
subdata = {
91-
'name': name if not subalias else f"{name} ({', '.join(subalias)})",
91+
'name': name if not subalias else f'{name} ({", ".join(subalias)})',
9292
'help': helps.get(name, ''),
9393
'usage': subaction.format_usage().strip(),
9494
'bare_usage': _format_usage_without_prefix(subaction),

sphinxarg/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def command_pos_args(result: dict) -> str:
2323
ret = ''
2424

2525
if 'name' in result and result['name'] != '':
26-
ret += f"{result['name']}"
26+
ret += f'{result["name"]}'
2727
elif 'prog' in result and result['prog'] != '':
28-
ret += f"{result['prog']}"
28+
ret += f'{result["prog"]}'
2929

3030
if 'parent' in result:
3131
ret = command_pos_args(result['parent']) + ' ' + ret

test/test_default_html.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,12 @@ def test_object_inventory(app, cached_etree_parse):
101101

102102
directive_opts = inv.get('commands:command').get('sample-directive-opts', None)
103103
assert directive_opts is not None
104-
assert (
105-
'test/path/index.html#sample-directive-opts'
106-
== directive_opts.uri
107-
)
104+
assert 'test/path/index.html#sample-directive-opts' == directive_opts.uri
108105

109106
directive_opts_a = inv.get('commands:command').get('sample-directive-opts A', None)
110107
assert directive_opts_a is not None
111-
assert (
112-
'test/path/subcommand-a.html#sample-directive-opts-A'
113-
== directive_opts_a.uri
114-
)
108+
assert 'test/path/subcommand-a.html#sample-directive-opts-A' == directive_opts_a.uri
115109

116110
directive_opts_b = inv.get('commands:command').get('sample-directive-opts B', None)
117111
assert directive_opts_b is not None
118-
assert (
119-
'test/path/index.html#sample-directive-opts-B'
120-
== directive_opts_b.uri
121-
)
112+
assert 'test/path/index.html#sample-directive-opts-B' == directive_opts_b.uri

0 commit comments

Comments
 (0)