mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Improve uses of `str.join` with a throwaway list
This commit is contained in:
@@ -1803,7 +1803,7 @@ class ASTOperatorType(ASTOperator):
|
||||
return 'cv' + self.type.get_id(version)
|
||||
|
||||
def _stringify(self, transform: StringifyTransform) -> str:
|
||||
return ''.join(['operator ', transform(self.type)])
|
||||
return f'operator {transform(self.type)}'
|
||||
|
||||
def get_name_no_template(self) -> str:
|
||||
return str(self)
|
||||
@@ -8218,7 +8218,7 @@ class CPPDomain(Domain):
|
||||
rootSymbol = self.data['root_symbol']
|
||||
parentSymbol = rootSymbol.direct_lookup(parentKey)
|
||||
parentName = parentSymbol.get_full_nested_name()
|
||||
return '::'.join([str(parentName), target])
|
||||
return f'{parentName}::{target}'
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> dict[str, Any]:
|
||||
|
||||
@@ -89,12 +89,12 @@ class JSObject(ObjectDescription[tuple[str, str]]):
|
||||
finally:
|
||||
name = member_name
|
||||
if prefix and member_prefix:
|
||||
prefix = '.'.join([prefix, member_prefix])
|
||||
prefix = f'{prefix}.{member_prefix}'
|
||||
elif prefix is None and member_prefix:
|
||||
prefix = member_prefix
|
||||
fullname = name
|
||||
if prefix:
|
||||
fullname = '.'.join([prefix, name])
|
||||
fullname = f'{prefix}.{name}'
|
||||
|
||||
signode['module'] = mod_name
|
||||
signode['object'] = prefix
|
||||
@@ -443,11 +443,11 @@ class JavaScriptDomain(Domain):
|
||||
|
||||
searches = []
|
||||
if mod_name and prefix:
|
||||
searches.append('.'.join([mod_name, prefix, name]))
|
||||
searches.append(f'{mod_name}.{prefix}.{name}')
|
||||
if mod_name:
|
||||
searches.append('.'.join([mod_name, name]))
|
||||
searches.append(f'{mod_name}.{name}')
|
||||
if prefix:
|
||||
searches.append('.'.join([prefix, name]))
|
||||
searches.append(f'{prefix}.{name}')
|
||||
searches.append(name)
|
||||
|
||||
if searchorder == 0:
|
||||
|
||||
@@ -1111,7 +1111,7 @@ class PyMethod(PyObject):
|
||||
try:
|
||||
clsname, methname = name.rsplit('.', 1)
|
||||
if modname and self.env.config.add_module_names:
|
||||
clsname = '.'.join([modname, clsname])
|
||||
clsname = f'{modname}.{clsname}'
|
||||
except ValueError:
|
||||
if modname:
|
||||
return _('%s() (in module %s)') % (name, modname)
|
||||
@@ -1201,7 +1201,7 @@ class PyAttribute(PyObject):
|
||||
try:
|
||||
clsname, attrname = name.rsplit('.', 1)
|
||||
if modname and self.env.config.add_module_names:
|
||||
clsname = '.'.join([modname, clsname])
|
||||
clsname = f'{modname}.{clsname}'
|
||||
except ValueError:
|
||||
if modname:
|
||||
return _('%s (in module %s)') % (name, modname)
|
||||
@@ -1252,7 +1252,7 @@ class PyProperty(PyObject):
|
||||
try:
|
||||
clsname, attrname = name.rsplit('.', 1)
|
||||
if modname and self.env.config.add_module_names:
|
||||
clsname = '.'.join([modname, clsname])
|
||||
clsname = f'{modname}.{clsname}'
|
||||
except ValueError:
|
||||
if modname:
|
||||
return _('%s (in module %s)') % (name, modname)
|
||||
|
||||
@@ -168,8 +168,8 @@ class ReSTDirectiveOption(ReSTMarkup):
|
||||
|
||||
directive_name = self.current_directive
|
||||
if directive_name:
|
||||
prefix = '-'.join([self.objtype, directive_name])
|
||||
objname = ':'.join([directive_name, name])
|
||||
prefix = f'{self.objtype}-{directive_name}'
|
||||
objname = f'{directive_name}:{name}'
|
||||
else:
|
||||
prefix = self.objtype
|
||||
objname = name
|
||||
|
||||
@@ -229,7 +229,7 @@ class Cmdoption(ObjectDescription[str]):
|
||||
else:
|
||||
descr = _('command line option')
|
||||
for option in signode.get('allnames', []):
|
||||
entry = '; '.join([descr, option])
|
||||
entry = f'{descr}; {option}'
|
||||
self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None))
|
||||
|
||||
|
||||
@@ -1002,7 +1002,7 @@ class StandardDomain(Domain):
|
||||
yield (doc, clean_astext(self.env.titles[doc]), 'doc', doc, '', -1)
|
||||
for (prog, option), info in self.progoptions.items():
|
||||
if prog:
|
||||
fullname = ".".join([prog, option])
|
||||
fullname = f'{prog}.{option}'
|
||||
yield (fullname, fullname, 'cmdoption', info[0], info[1], 1)
|
||||
else:
|
||||
yield (option, option, 'cmdoption', info[0], info[1], 1)
|
||||
@@ -1091,7 +1091,8 @@ class StandardDomain(Domain):
|
||||
command.insert(0, progname)
|
||||
option = command.pop()
|
||||
if command:
|
||||
return '.'.join(['-'.join(command), option])
|
||||
command_str = '-'.join(command)
|
||||
return f'{command_str}.{option}'
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
|
||||
@@ -1266,7 +1266,7 @@ class DocstringSignatureMixin:
|
||||
self.args, self.retann = result
|
||||
sig = super().format_signature(**kwargs) # type: ignore[misc]
|
||||
if self._signatures:
|
||||
return "\n".join([sig] + self._signatures)
|
||||
return "\n".join((sig, *self._signatures))
|
||||
else:
|
||||
return sig
|
||||
|
||||
@@ -1673,7 +1673,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
||||
try:
|
||||
analyzer = ModuleAnalyzer.for_module(cls.__module__)
|
||||
analyzer.analyze()
|
||||
qualname = '.'.join([cls.__qualname__, self._signature_method_name])
|
||||
qualname = f'{cls.__qualname__}.{self._signature_method_name}'
|
||||
if qualname in analyzer.overloads:
|
||||
return analyzer.overloads.get(qualname, [])
|
||||
elif qualname in analyzer.tagorder:
|
||||
@@ -1694,7 +1694,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
||||
__qualname__ = None
|
||||
|
||||
if __modname__ and __qualname__:
|
||||
return '.'.join([__modname__, __qualname__])
|
||||
return f'{__modname__}.{__qualname__}'
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -2477,7 +2477,7 @@ class RuntimeInstanceAttributeMixin(DataDocumenterMixinBase):
|
||||
analyzer = ModuleAnalyzer.for_module(module)
|
||||
analyzer.analyze()
|
||||
if qualname and self.objpath:
|
||||
key = '.'.join([qualname, self.objpath[-1]])
|
||||
key = f'{qualname}.{self.objpath[-1]}'
|
||||
if key in analyzer.tagorder:
|
||||
return True
|
||||
except (AttributeError, PycodeError):
|
||||
|
||||
@@ -59,20 +59,20 @@ class DocumenterBridge:
|
||||
def process_documenter_options(documenter: type[Documenter], config: Config, options: dict,
|
||||
) -> Options:
|
||||
"""Recognize options of Documenter from user input."""
|
||||
default_options = config.autodoc_default_options
|
||||
for name in AUTODOC_DEFAULT_OPTIONS:
|
||||
if name not in documenter.option_spec:
|
||||
continue
|
||||
negated = options.pop('no-' + name, True) is None
|
||||
if name in config.autodoc_default_options and not negated:
|
||||
if name in options and isinstance(config.autodoc_default_options[name], str):
|
||||
if name in default_options and not negated:
|
||||
if name in options and isinstance(default_options[name], str):
|
||||
# take value from options if present or extend it
|
||||
# with autodoc_default_options if necessary
|
||||
if name in AUTODOC_EXTENDABLE_OPTIONS:
|
||||
if options[name] is not None and options[name].startswith('+'):
|
||||
options[name] = ','.join([config.autodoc_default_options[name],
|
||||
options[name][1:]])
|
||||
options[name] = f'{default_options[name]},{options[name][1:]}'
|
||||
else:
|
||||
options[name] = config.autodoc_default_options[name]
|
||||
options[name] = default_options[name]
|
||||
|
||||
elif options.get(name) is not None:
|
||||
# remove '+' from option argument if there's nothing to merge it with
|
||||
|
||||
@@ -50,7 +50,7 @@ def merge_typehints(app: Sphinx, domain: str, objtype: str, contentnode: Element
|
||||
try:
|
||||
signature = cast(addnodes.desc_signature, contentnode.parent[0])
|
||||
if signature['module']:
|
||||
fullname = '.'.join([signature['module'], signature['fullname']])
|
||||
fullname = f'{signature["module"]}.{signature["fullname"]}'
|
||||
else:
|
||||
fullname = signature['fullname']
|
||||
except KeyError:
|
||||
|
||||
@@ -642,7 +642,7 @@ def import_by_name(
|
||||
for prefix in prefixes:
|
||||
try:
|
||||
if prefix:
|
||||
prefixed_name = '.'.join([prefix, name])
|
||||
prefixed_name = f'{prefix}.{name}'
|
||||
else:
|
||||
prefixed_name = name
|
||||
obj, parent, modname = _import_by_name(prefixed_name, grouped_exception=True)
|
||||
|
||||
@@ -125,7 +125,7 @@ class TestDirective(SphinxDirective):
|
||||
if self.name == 'doctest' and 'pyversion' in self.options:
|
||||
try:
|
||||
spec = self.options['pyversion']
|
||||
python_version = '.'.join([str(v) for v in sys.version_info[:3]])
|
||||
python_version = '.'.join(map(str, sys.version_info[:3]))
|
||||
if not is_allowed_version(spec, python_version):
|
||||
flag = doctest.OPTIONFLAGS_BY_NAME['SKIP']
|
||||
node['options'][flag] = True # Skip the test
|
||||
|
||||
@@ -82,7 +82,7 @@ class ClickableMapDefinition:
|
||||
If not exists, this only returns empty string.
|
||||
"""
|
||||
if self.clickable:
|
||||
return '\n'.join([self.content[0]] + self.clickable + [self.content[-1]])
|
||||
return '\n'.join((self.content[0], *self.clickable, self.content[-1]))
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
@@ -270,10 +270,10 @@ class InheritanceGraph:
|
||||
}
|
||||
|
||||
def _format_node_attrs(self, attrs: dict[str, Any]) -> str:
|
||||
return ','.join(['%s=%s' % x for x in sorted(attrs.items())])
|
||||
return ','.join(f'{k}={v}' for k, v in sorted(attrs.items()))
|
||||
|
||||
def _format_graph_attrs(self, attrs: dict[str, Any]) -> str:
|
||||
return ''.join(['%s=%s;\n' % x for x in sorted(attrs.items())])
|
||||
return ''.join(f'{k}={v};\n' for k, v in sorted(attrs.items()))
|
||||
|
||||
def generate_dot(self, name: str, urls: dict[str, str] | None = None,
|
||||
env: BuildEnvironment | None = None,
|
||||
|
||||
@@ -245,7 +245,7 @@ def fetch_inventory_group(
|
||||
for fail in failures:
|
||||
logger.info(*fail)
|
||||
else:
|
||||
issues = '\n'.join([f[0] % f[1:] for f in failures])
|
||||
issues = '\n'.join(f[0] % f[1:] for f in failures)
|
||||
logger.warning(__("failed to reach any of the inventories "
|
||||
"with the following issues:") + "\n" + issues)
|
||||
|
||||
|
||||
@@ -1183,13 +1183,13 @@ class NumpyDocstring(GoogleDocstring):
|
||||
elif filepath is None:
|
||||
filepath = ""
|
||||
|
||||
return ":".join([filepath, "docstring of %s" % name])
|
||||
return f"{filepath}:docstring of {name}"
|
||||
|
||||
def _escape_args_and_kwargs(self, name: str) -> str:
|
||||
func = super()._escape_args_and_kwargs
|
||||
|
||||
if ", " in name:
|
||||
return ", ".join(func(param) for param in name.split(", "))
|
||||
return ", ".join(map(func, name.split(", ")))
|
||||
else:
|
||||
return func(name)
|
||||
|
||||
|
||||
@@ -121,8 +121,10 @@ class _UnparseVisitor(ast.NodeVisitor):
|
||||
return op.join(self.visit(e) for e in node.values)
|
||||
|
||||
def visit_Call(self, node: ast.Call) -> str:
|
||||
args = ', '.join([self.visit(e) for e in node.args]
|
||||
+ [f"{k.arg}={self.visit(k.value)}" for k in node.keywords])
|
||||
args = ', '.join(
|
||||
[self.visit(e) for e in node.args]
|
||||
+ [f"{k.arg}={self.visit(k.value)}" for k in node.keywords],
|
||||
)
|
||||
return f"{self.visit(node.func)}({args})"
|
||||
|
||||
def visit_Constant(self, node: ast.Constant) -> str:
|
||||
|
||||
@@ -404,8 +404,7 @@ class ManpageLink(SphinxTransform):
|
||||
|
||||
def apply(self, **kwargs: Any) -> None:
|
||||
for node in self.document.findall(addnodes.manpage):
|
||||
manpage = ' '.join([str(x) for x in node.children
|
||||
if isinstance(x, nodes.Text)])
|
||||
manpage = ' '.join(str(x) for x in node.children if isinstance(x, nodes.Text))
|
||||
pattern = r'^(?P<path>(?P<page>.+)[\(\.](?P<section>[1-9]\w*)?\)?)$'
|
||||
info = {'path': manpage,
|
||||
'page': manpage,
|
||||
|
||||
@@ -150,7 +150,7 @@ class Table:
|
||||
line.append(Cell())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "\n".join(repr(line) for line in self.lines)
|
||||
return "\n".join(map(repr, self.lines))
|
||||
|
||||
def cell_width(self, cell: Cell, source: list[int]) -> int:
|
||||
"""Give the cell width, according to the given source (either
|
||||
|
||||
@@ -43,4 +43,4 @@ def test_sectioning(app, status, warning):
|
||||
for i, s in enumerate(parts):
|
||||
testsects(str(i + 1) + '.', s, 4)
|
||||
assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \
|
||||
'\n'.join([p[0] for p in parts])
|
||||
'\n'.join(p[0] for p in parts)
|
||||
|
||||
Reference in New Issue
Block a user