Skip to content

Commit f1bf5b8

Browse files
authored
Merge pull request #10516 from AA-Turner/simplifications
Remove redundant code
2 parents 04cdac2 + 4e48130 commit f1bf5b8

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

sphinx/builders/html/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def hasdoc(name: str) -> bool:
10551055
# sort JS/CSS before rendering HTML
10561056
try:
10571057
# Convert script_files to list to support non-list script_files (refs: #8889)
1058-
ctx['script_files'] = sorted(list(ctx['script_files']), key=lambda js: js.priority)
1058+
ctx['script_files'] = sorted(ctx['script_files'], key=lambda js: js.priority)
10591059
except AttributeError:
10601060
# Skip sorting if users modifies script_files directly (maybe via `html_context`).
10611061
# refs: #8885
@@ -1064,7 +1064,7 @@ def hasdoc(name: str) -> bool:
10641064
pass
10651065

10661066
try:
1067-
ctx['css_files'] = sorted(list(ctx['css_files']), key=lambda css: css.priority)
1067+
ctx['css_files'] = sorted(ctx['css_files'], key=lambda css: css.priority)
10681068
except AttributeError:
10691069
pass
10701070

sphinx/domains/c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ def _parse_expression_fallback(
25312531
while not self.eof:
25322532
if (len(symbols) == 0 and self.current_char in end):
25332533
break
2534-
if self.current_char in brackets.keys():
2534+
if self.current_char in brackets:
25352535
symbols.append(brackets[self.current_char])
25362536
elif len(symbols) > 0 and self.current_char == symbols[-1]:
25372537
symbols.pop()

sphinx/domains/cpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5754,7 +5754,7 @@ def _parse_expression_fallback(self, end: List[str],
57545754
while not self.eof:
57555755
if (len(symbols) == 0 and self.current_char in end):
57565756
break
5757-
if self.current_char in brackets.keys():
5757+
if self.current_char in brackets:
57585758
symbols.append(brackets[self.current_char])
57595759
elif len(symbols) > 0 and self.current_char == symbols[-1]:
57605760
symbols.pop()

sphinx/ext/autosummary/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def get_items(self, names: List[str]) -> List[Tuple[str, str, str, str]]:
315315
try:
316316
real_name, obj, parent, modname = self.import_by_name(name, prefixes=prefixes)
317317
except ImportExceptionGroup as exc:
318-
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exc.exceptions))
318+
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exc.exceptions})
319319
logger.warning(__('autosummary: failed to import %s.\nPossible hints:\n%s'),
320320
name, '\n'.join(errors), location=self.get_location())
321321
continue

sphinx/ext/autosummary/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
355355
suffix: str = '.rst', base_path: str = None,
356356
imported_members: bool = False, app: Any = None,
357357
overwrite: bool = True, encoding: str = 'utf-8') -> None:
358-
showed_sources = list(sorted(sources))
358+
showed_sources = sorted(sources)
359359
if len(showed_sources) > 20:
360360
showed_sources = showed_sources[:10] + ['...'] + showed_sources[-10:]
361361
logger.info(__('[autosummary] generating autosummary for: %s') %
@@ -404,7 +404,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
404404
else:
405405
exceptions = exc.exceptions + [exc2]
406406

407-
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exceptions))
407+
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exceptions})
408408
logger.warning(__('[autosummary] failed to import %s.\nPossible hints:\n%s'),
409409
entry.name, '\n'.join(errors))
410410
continue
@@ -468,7 +468,7 @@ def find_autosummary_in_docstring(name: str, filename: str = None) -> List[Autos
468468
except AttributeError:
469469
pass
470470
except ImportExceptionGroup as exc:
471-
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exc.exceptions))
471+
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exc.exceptions})
472472
print('Failed to import %s.\nPossible hints:\n%s' % (name, '\n'.join(errors)))
473473
except SystemExit:
474474
print("Failed to import '%s'; the module executes module level "

sphinx/ext/napoleon/docstring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,12 @@ def postprocess(item):
931931
else:
932932
return [item]
933933

934-
tokens = list(
934+
tokens = [
935935
item
936936
for raw_token in _token_regex.split(spec)
937937
for item in postprocess(raw_token)
938938
if item
939-
)
939+
]
940940
return tokens
941941

942942

sphinx/util/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def encode_uri(uri: str) -> str:
424424
split = list(urlsplit(uri))
425425
split[1] = split[1].encode('idna').decode('ascii')
426426
split[2] = quote_plus(split[2].encode(), '/')
427-
query = list((q, v.encode()) for (q, v) in parse_qsl(split[3]))
427+
query = [(q, v.encode()) for (q, v) in parse_qsl(split[3])]
428428
split[3] = urlencode(query)
429429
return urlunsplit(split)
430430

sphinx/util/cfamily.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def _parse_balanced_token_seq(self, end: List[str]) -> str:
379379
while not self.eof:
380380
if len(symbols) == 0 and self.current_char in end:
381381
break
382-
if self.current_char in brackets.keys():
382+
if self.current_char in brackets:
383383
symbols.append(brackets[self.current_char])
384384
elif len(symbols) > 0 and self.current_char == symbols[-1]:
385385
symbols.pop()

tests/test_domain_cpp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,11 +1113,11 @@ def test_domain_cpp_build_misuse_of_roles(app, status, warning):
11131113
if targetType == 'templateParam':
11141114
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
11151115
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
1116-
warn = list(sorted(warn))
1116+
warn = sorted(warn)
11171117
for w in ws:
11181118
assert "targets a" in w
11191119
ws = [w[w.index("WARNING:"):] for w in ws]
1120-
ws = list(sorted(ws))
1120+
ws = sorted(ws)
11211121
print("Expected warnings:")
11221122
for w in warn:
11231123
print(w)

tests/test_ext_napoleon_iterators.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ def test_iter(self):
5555
self.assertTrue(it is it.__iter__())
5656

5757
a = []
58-
b = [i for i in peek_iter(a)]
58+
b = list(peek_iter(a))
5959
self.assertEqual([], b)
6060

6161
a = ['1']
62-
b = [i for i in peek_iter(a)]
62+
b = list(peek_iter(a))
6363
self.assertEqual(['1'], b)
6464

6565
a = ['1', '2']
66-
b = [i for i in peek_iter(a)]
66+
b = list(peek_iter(a))
6767
self.assertEqual(['1', '2'], b)
6868

6969
a = ['1', '2', '3']
70-
b = [i for i in peek_iter(a)]
70+
b = list(peek_iter(a))
7171
self.assertEqual(['1', '2', '3'], b)
7272

7373
def test_next_with_multi(self):
@@ -303,7 +303,7 @@ def get_next():
303303
return next(a)
304304
it = modify_iter(get_next, sentinel, int)
305305
expected = [1, 2, 3]
306-
self.assertEqual(expected, [i for i in it])
306+
self.assertEqual(expected, list(it))
307307

308308
def test_init_with_sentinel_kwargs(self):
309309
a = iter([1, 2, 3, 4])
@@ -313,13 +313,13 @@ def get_next():
313313
return next(a)
314314
it = modify_iter(get_next, sentinel, modifier=str)
315315
expected = ['1', '2', '3']
316-
self.assertEqual(expected, [i for i in it])
316+
self.assertEqual(expected, list(it))
317317

318318
def test_modifier_default(self):
319319
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
320320
it = modify_iter(a)
321321
expected = ['', ' ', ' a ', 'b ', ' c', ' ', '']
322-
self.assertEqual(expected, [i for i in it])
322+
self.assertEqual(expected, list(it))
323323

324324
def test_modifier_not_callable(self):
325325
self.assertRaises(TypeError, modify_iter, [1], modifier='not_callable')
@@ -328,10 +328,10 @@ def test_modifier_rstrip(self):
328328
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
329329
it = modify_iter(a, modifier=lambda s: s.rstrip())
330330
expected = ['', '', ' a', 'b', ' c', '', '']
331-
self.assertEqual(expected, [i for i in it])
331+
self.assertEqual(expected, list(it))
332332

333333
def test_modifier_rstrip_unicode(self):
334334
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
335335
it = modify_iter(a, modifier=lambda s: s.rstrip())
336336
expected = ['', '', ' a', 'b', ' c', '', '']
337-
self.assertEqual(expected, [i for i in it])
337+
self.assertEqual(expected, list(it))

0 commit comments

Comments
 (0)