Merge pull request #10516 from AA-Turner/simplifications

Remove redundant code
This commit is contained in:
Takeshi KOMIYA
2022-06-07 00:10:15 +09:00
committed by GitHub
10 changed files with 23 additions and 23 deletions

View File

@@ -1055,7 +1055,7 @@ class StandaloneHTMLBuilder(Builder):
# sort JS/CSS before rendering HTML
try:
# Convert script_files to list to support non-list script_files (refs: #8889)
ctx['script_files'] = sorted(list(ctx['script_files']), key=lambda js: js.priority)
ctx['script_files'] = sorted(ctx['script_files'], key=lambda js: js.priority)
except AttributeError:
# Skip sorting if users modifies script_files directly (maybe via `html_context`).
# refs: #8885
@@ -1064,7 +1064,7 @@ class StandaloneHTMLBuilder(Builder):
pass
try:
ctx['css_files'] = sorted(list(ctx['css_files']), key=lambda css: css.priority)
ctx['css_files'] = sorted(ctx['css_files'], key=lambda css: css.priority)
except AttributeError:
pass

View File

@@ -2531,7 +2531,7 @@ class DefinitionParser(BaseParser):
while not self.eof:
if (len(symbols) == 0 and self.current_char in end):
break
if self.current_char in brackets.keys():
if self.current_char in brackets:
symbols.append(brackets[self.current_char])
elif len(symbols) > 0 and self.current_char == symbols[-1]:
symbols.pop()

View File

@@ -5754,7 +5754,7 @@ class DefinitionParser(BaseParser):
while not self.eof:
if (len(symbols) == 0 and self.current_char in end):
break
if self.current_char in brackets.keys():
if self.current_char in brackets:
symbols.append(brackets[self.current_char])
elif len(symbols) > 0 and self.current_char == symbols[-1]:
symbols.pop()

View File

@@ -315,7 +315,7 @@ class Autosummary(SphinxDirective):
try:
real_name, obj, parent, modname = self.import_by_name(name, prefixes=prefixes)
except ImportExceptionGroup as exc:
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exc.exceptions))
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exc.exceptions})
logger.warning(__('autosummary: failed to import %s.\nPossible hints:\n%s'),
name, '\n'.join(errors), location=self.get_location())
continue

View File

@@ -355,7 +355,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
suffix: str = '.rst', base_path: str = None,
imported_members: bool = False, app: Any = None,
overwrite: bool = True, encoding: str = 'utf-8') -> None:
showed_sources = list(sorted(sources))
showed_sources = sorted(sources)
if len(showed_sources) > 20:
showed_sources = showed_sources[:10] + ['...'] + showed_sources[-10:]
logger.info(__('[autosummary] generating autosummary for: %s') %
@@ -404,7 +404,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
else:
exceptions = exc.exceptions + [exc2]
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exceptions))
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exceptions})
logger.warning(__('[autosummary] failed to import %s.\nPossible hints:\n%s'),
entry.name, '\n'.join(errors))
continue
@@ -468,7 +468,7 @@ def find_autosummary_in_docstring(name: str, filename: str = None) -> List[Autos
except AttributeError:
pass
except ImportExceptionGroup as exc:
errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exc.exceptions))
errors = list({"* %s: %s" % (type(e).__name__, e) for e in exc.exceptions})
print('Failed to import %s.\nPossible hints:\n%s' % (name, '\n'.join(errors)))
except SystemExit:
print("Failed to import '%s'; the module executes module level "

View File

@@ -931,12 +931,12 @@ def _tokenize_type_spec(spec: str) -> List[str]:
else:
return [item]
tokens = list(
tokens = [
item
for raw_token in _token_regex.split(spec)
for item in postprocess(raw_token)
if item
)
]
return tokens

View File

@@ -424,7 +424,7 @@ def encode_uri(uri: str) -> str:
split = list(urlsplit(uri))
split[1] = split[1].encode('idna').decode('ascii')
split[2] = quote_plus(split[2].encode(), '/')
query = list((q, v.encode()) for (q, v) in parse_qsl(split[3]))
query = [(q, v.encode()) for (q, v) in parse_qsl(split[3])]
split[3] = urlencode(query)
return urlunsplit(split)

View File

@@ -379,7 +379,7 @@ class BaseParser:
while not self.eof:
if len(symbols) == 0 and self.current_char in end:
break
if self.current_char in brackets.keys():
if self.current_char in brackets:
symbols.append(brackets[self.current_char])
elif len(symbols) > 0 and self.current_char == symbols[-1]:
symbols.pop()

View File

@@ -1113,11 +1113,11 @@ def test_domain_cpp_build_misuse_of_roles(app, status, warning):
if targetType == 'templateParam':
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
warn = list(sorted(warn))
warn = sorted(warn)
for w in ws:
assert "targets a" in w
ws = [w[w.index("WARNING:"):] for w in ws]
ws = list(sorted(ws))
ws = sorted(ws)
print("Expected warnings:")
for w in warn:
print(w)

View File

@@ -55,19 +55,19 @@ class PeekIterTest(BaseIteratorsTest):
self.assertTrue(it is it.__iter__())
a = []
b = [i for i in peek_iter(a)]
b = list(peek_iter(a))
self.assertEqual([], b)
a = ['1']
b = [i for i in peek_iter(a)]
b = list(peek_iter(a))
self.assertEqual(['1'], b)
a = ['1', '2']
b = [i for i in peek_iter(a)]
b = list(peek_iter(a))
self.assertEqual(['1', '2'], b)
a = ['1', '2', '3']
b = [i for i in peek_iter(a)]
b = list(peek_iter(a))
self.assertEqual(['1', '2', '3'], b)
def test_next_with_multi(self):
@@ -303,7 +303,7 @@ class ModifyIterTest(BaseIteratorsTest):
return next(a)
it = modify_iter(get_next, sentinel, int)
expected = [1, 2, 3]
self.assertEqual(expected, [i for i in it])
self.assertEqual(expected, list(it))
def test_init_with_sentinel_kwargs(self):
a = iter([1, 2, 3, 4])
@@ -313,13 +313,13 @@ class ModifyIterTest(BaseIteratorsTest):
return next(a)
it = modify_iter(get_next, sentinel, modifier=str)
expected = ['1', '2', '3']
self.assertEqual(expected, [i for i in it])
self.assertEqual(expected, list(it))
def test_modifier_default(self):
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
it = modify_iter(a)
expected = ['', ' ', ' a ', 'b ', ' c', ' ', '']
self.assertEqual(expected, [i for i in it])
self.assertEqual(expected, list(it))
def test_modifier_not_callable(self):
self.assertRaises(TypeError, modify_iter, [1], modifier='not_callable')
@@ -328,10 +328,10 @@ class ModifyIterTest(BaseIteratorsTest):
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
it = modify_iter(a, modifier=lambda s: s.rstrip())
expected = ['', '', ' a', 'b', ' c', '', '']
self.assertEqual(expected, [i for i in it])
self.assertEqual(expected, list(it))
def test_modifier_rstrip_unicode(self):
a = ['', ' ', ' a ', 'b ', ' c', ' ', '']
it = modify_iter(a, modifier=lambda s: s.rstrip())
expected = ['', '', ' a', 'b', ' c', '', '']
self.assertEqual(expected, [i for i in it])
self.assertEqual(expected, list(it))