Run the `pyupgrade` tool

This commit is contained in:
Adam Turner 2022-10-17 15:54:59 +01:00
parent b277abcb49
commit 920828fe35
52 changed files with 119 additions and 129 deletions

View File

@ -158,7 +158,7 @@ def linkify_issues_in_changelog(app, docname, source):
def linkify(match):
url = 'https://github.com/sphinx-doc/sphinx/issues/' + match[1]
return '`{} <{}>`_'.format(match[0], url)
return f'`{match[0]} <{url}>`_'
linkified_changelog = re.sub(r'(?:PR)?#([0-9]+)\b', linkify, changelog)

View File

@ -140,8 +140,8 @@ class RecipeDomain(Domain):
def add_recipe(self, signature, ingredients):
"""Add a new recipe to the domain."""
name = '{}.{}'.format('recipe', signature)
anchor = 'recipe-{}'.format(signature)
name = f'recipe.{signature}'
anchor = f'recipe-{signature}'
self.data['recipe_ingredients'][name] = ingredients
# name, dispname, type, docname, anchor, priority

View File

@ -142,8 +142,7 @@ def example_generator(n):
[0, 1, 2, 3]
"""
for i in range(n):
yield i
yield from range(n)
class ExampleError(Exception):

View File

@ -180,8 +180,7 @@ def example_generator(n):
[0, 1, 2, 3]
"""
for i in range(n):
yield i
yield from range(n)
class ExampleError(Exception):

View File

@ -43,8 +43,7 @@ if _in_development:
ret = subprocess.run(
['git', 'show', '-s', '--pretty=format:%h'],
cwd=package_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
encoding='ascii',
).stdout
if ret:

View File

@ -244,7 +244,7 @@ class desc_parameterlist(nodes.Part, nodes.Inline, nodes.FixedTextElement):
child_text_separator = ', '
def astext(self):
return '({})'.format(super().astext())
return f'({super().astext()})'
class desc_parameter(nodes.Part, nodes.Inline, nodes.FixedTextElement):

View File

@ -364,7 +364,7 @@ def generate(
if overwrite or not path.isfile(fpath):
if 'quiet' not in d:
print(__('Creating file %s.') % fpath)
with open(fpath, 'wt', encoding='utf-8', newline=newline) as f:
with open(fpath, 'w', encoding='utf-8', newline=newline) as f:
f.write(content)
else:
if 'quiet' not in d:

View File

@ -464,7 +464,7 @@ def check_confval_types(app: Optional["Sphinx"], config: Config) -> None:
if annotations:
msg = __("The config value `{name}' has type `{current.__name__}'; "
"expected {permitted}.")
wrapped_annotations = ["`{}'".format(c.__name__) for c in annotations]
wrapped_annotations = [f"`{c.__name__}'" for c in annotations]
if len(wrapped_annotations) > 2:
permitted = "{}, or {}".format(
", ".join(wrapped_annotations[:-1]),

View File

@ -1826,7 +1826,7 @@ class Symbol:
Symbol.debug_indent += 1
Symbol.debug_print("nn: ", nestedName)
Symbol.debug_print("decl: ", declaration)
Symbol.debug_print("location: {}:{}".format(docname, line))
Symbol.debug_print(f"location: {docname}:{line}")
def onMissingQualifiedSymbol(parentSymbol: "Symbol", ident: ASTIdentifier) -> "Symbol":
if Symbol.debug_lookup:
@ -1852,7 +1852,7 @@ class Symbol:
Symbol.debug_indent += 1
Symbol.debug_print("ident: ", lookupResult.ident)
Symbol.debug_print("declaration: ", declaration)
Symbol.debug_print("location: {}:{}".format(docname, line))
Symbol.debug_print(f"location: {docname}:{line}")
Symbol.debug_indent -= 1
symbol = Symbol(parent=lookupResult.parentSymbol,
ident=lookupResult.ident,

View File

@ -954,7 +954,7 @@ class ASTUserDefinedLiteral(ASTLiteral):
def get_id(self, version: int) -> str:
# mangle as if it was a function call: ident(literal)
return 'clL_Zli{}E{}E'.format(self.ident.get_id(version), self.literal.get_id(version))
return f'clL_Zli{self.ident.get_id(version)}E{self.literal.get_id(version)}E'
def describe_signature(self, signode: TextElement, mode: str,
env: "BuildEnvironment", symbol: "Symbol") -> None:
@ -4635,7 +4635,7 @@ class Symbol:
Symbol.debug_print("tdecls:", ",".join(str(t) for t in templateDecls))
Symbol.debug_print("nn: ", nestedName)
Symbol.debug_print("decl: ", declaration)
Symbol.debug_print("location: {}:{}".format(docname, line))
Symbol.debug_print(f"location: {docname}:{line}")
def onMissingQualifiedSymbol(parentSymbol: "Symbol",
identOrOp: Union[ASTIdentifier, ASTOperator],
@ -4673,7 +4673,7 @@ class Symbol:
Symbol.debug_print("identOrOp: ", lookupResult.identOrOp)
Symbol.debug_print("templateArgs: ", lookupResult.templateArgs)
Symbol.debug_print("declaration: ", declaration)
Symbol.debug_print("location: {}:{}".format(docname, line))
Symbol.debug_print(f"location: {docname}:{line}")
Symbol.debug_indent -= 1
symbol = Symbol(parent=lookupResult.parentSymbol,
identOrOp=lookupResult.identOrOp,
@ -6025,23 +6025,23 @@ class DefinitionParser(BaseParser):
'float', 'double',
'__float80', '_Float64x', '__float128', '_Float128'):
if typ is not None:
self.fail("Can not have both {} and {}.".format(t, typ))
self.fail(f"Can not have both {t} and {typ}.")
typ = t
elif t in ('signed', 'unsigned'):
if signedness is not None:
self.fail("Can not have both {} and {}.".format(t, signedness))
self.fail(f"Can not have both {t} and {signedness}.")
signedness = t
elif t == 'short':
if len(width) != 0:
self.fail("Can not have both {} and {}.".format(t, width[0]))
self.fail(f"Can not have both {t} and {width[0]}.")
width.append(t)
elif t == 'long':
if len(width) != 0 and width[0] != 'long':
self.fail("Can not have both {} and {}.".format(t, width[0]))
self.fail(f"Can not have both {t} and {width[0]}.")
width.append(t)
elif t in ('_Imaginary', '_Complex'):
if modifier is not None:
self.fail("Can not have both {} and {}.".format(t, modifier))
self.fail(f"Can not have both {t} and {modifier}.")
modifier = t
self.skip_ws()
if len(names) == 0:
@ -6051,41 +6051,41 @@ class DefinitionParser(BaseParser):
'wchar_t', 'char8_t', 'char16_t', 'char32_t',
'__float80', '_Float64x', '__float128', '_Float128'):
if modifier is not None:
self.fail("Can not have both {} and {}.".format(typ, modifier))
self.fail(f"Can not have both {typ} and {modifier}.")
if signedness is not None:
self.fail("Can not have both {} and {}.".format(typ, signedness))
self.fail(f"Can not have both {typ} and {signedness}.")
if len(width) != 0:
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
elif typ == 'char':
if modifier is not None:
self.fail("Can not have both {} and {}.".format(typ, modifier))
self.fail(f"Can not have both {typ} and {modifier}.")
if len(width) != 0:
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
elif typ == 'int':
if modifier is not None:
self.fail("Can not have both {} and {}.".format(typ, modifier))
self.fail(f"Can not have both {typ} and {modifier}.")
elif typ in ('__int64', '__int128'):
if modifier is not None:
self.fail("Can not have both {} and {}.".format(typ, modifier))
self.fail(f"Can not have both {typ} and {modifier}.")
if len(width) != 0:
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
elif typ == 'float':
if signedness is not None:
self.fail("Can not have both {} and {}.".format(typ, signedness))
self.fail(f"Can not have both {typ} and {signedness}.")
if len(width) != 0:
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
elif typ == 'double':
if signedness is not None:
self.fail("Can not have both {} and {}.".format(typ, signedness))
self.fail(f"Can not have both {typ} and {signedness}.")
if len(width) > 1:
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
if len(width) == 1 and width[0] != 'long':
self.fail("Can not have both {} and {}.".format(typ, ' '.join(width)))
elif typ is None:
if modifier is not None:
self.fail("Can not have {} without a floating point type.".format(modifier))
self.fail(f"Can not have {modifier} without a floating point type.")
else:
raise AssertionError("Unhandled type {}".format(typ))
raise AssertionError(f"Unhandled type {typ}")
canonNames: List[str] = []
if modifier is not None:

View File

@ -76,8 +76,9 @@ versioning_conditions: Dict[str, Union[bool, Callable]] = {
if TYPE_CHECKING:
from collections.abc import MutableMapping
from typing import Literal
from typing_extensions import Literal, overload
from typing_extensions import overload
from sphinx.domains.c import CDomain
from sphinx.domains.changeset import ChangeSetDomain

View File

@ -5,7 +5,7 @@ import posixpath
import re
import subprocess
from os import path
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
from typing import Any, Dict, List, Optional, Tuple
from docutils import nodes
@ -244,7 +244,7 @@ def render_dot(self: SphinxTranslator, code: str, options: Dict, format: str,
dot_args.extend(['-Tcmapx', '-o%s.map' % outfn])
try:
ret = subprocess.run(dot_args, input=code.encode(), stdout=PIPE, stderr=PIPE,
ret = subprocess.run(dot_args, input=code.encode(), capture_output=True,
cwd=cwd, check=True)
if not path.isfile(outfn):
raise GraphvizError(__('dot did not produce an output file:\n[stderr]\n%r\n'

View File

@ -2,7 +2,7 @@
import subprocess
import sys
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
from typing import Any, Dict
import sphinx
@ -28,7 +28,7 @@ class ImagemagickConverter(ImageConverter):
try:
args = [self.config.image_converter, '-version']
logger.debug('Invoking %r ...', args)
subprocess.run(args, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(args, capture_output=True, check=True)
return True
except OSError as exc:
logger.warning(__(
@ -56,7 +56,7 @@ class ImagemagickConverter(ImageConverter):
self.config.image_converter_args +
[_from, _to])
logger.debug('Invoking %r ...', args)
subprocess.run(args, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(args, capture_output=True, check=True)
return True
except OSError:
logger.warning(__('convert command %r cannot be run, '

View File

@ -6,7 +6,7 @@ import shutil
import subprocess
import tempfile
from os import path
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
from typing import Any, Dict, List, Optional, Tuple
from docutils import nodes
@ -130,7 +130,7 @@ def compile_math(latex: str, builder: Builder) -> str:
command.append('math.tex')
try:
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True,
subprocess.run(command, capture_output=True, cwd=tempdir, check=True,
encoding='ascii')
return path.join(tempdir, 'math.dvi')
except OSError as exc:
@ -145,7 +145,7 @@ def compile_math(latex: str, builder: Builder) -> str:
def convert_dvi_to_image(command: List[str], name: str) -> Tuple[str, str]:
"""Convert DVI file to specific image format."""
try:
ret = subprocess.run(command, stdout=PIPE, stderr=PIPE, check=True, encoding='ascii')
ret = subprocess.run(command, capture_output=True, check=True, encoding='ascii')
return ret.stdout, ret.stderr
except OSError as exc:
logger.warning(__('%s command %r cannot be run (needed for math '

View File

@ -141,9 +141,9 @@ def _get_safe_url(url: str) -> str:
else:
frags = list(parts)
if parts.port:
frags[1] = '{}@{}:{}'.format(parts.username, parts.hostname, parts.port)
frags[1] = f'{parts.username}@{parts.hostname}:{parts.port}'
else:
frags[1] = '{}@{}'.format(parts.username, parts.hostname)
frags[1] = f'{parts.username}@{parts.hostname}'
return urlunsplit(frags)
@ -334,7 +334,7 @@ def _resolve_reference_in_domain(env: BuildEnvironment,
objtypes.append('method')
# the inventory contains domain:type as objtype
objtypes = ["{}:{}".format(domain.name, t) for t in objtypes]
objtypes = [f"{domain.name}:{t}" for t in objtypes]
# now that the objtypes list is complete we can remove the disabled ones
if honor_disabled_refs:

View File

@ -213,7 +213,7 @@ def should_generate_module_page(app: Sphinx, modname: str) -> bool:
if path.getmtime(module_filename) <= path.getmtime(page_filename):
# generation is not needed if the HTML page is newer than module file.
return False
except IOError:
except OSError:
pass
return True

View File

@ -70,7 +70,7 @@ class _UnparseVisitor(ast.NodeVisitor):
def _visit_op(self, node: ast.AST) -> str:
return OPERATORS[node.__class__]
for _op in OPERATORS:
locals()['visit_{}'.format(_op.__name__)] = _visit_op
locals()[f'visit_{_op.__name__}'] = _visit_op
def visit_arg(self, node: ast.arg) -> str:
if node.annotation:

View File

@ -4,7 +4,6 @@ import subprocess
import sys
from collections import namedtuple
from io import StringIO
from subprocess import PIPE
from typing import Any, Callable, Dict, Generator, Optional, Tuple
import pytest
@ -205,7 +204,7 @@ def if_graphviz_found(app: SphinxTestApp) -> None:
graphviz_dot = getattr(app.config, 'graphviz_dot', '')
try:
if graphviz_dot:
subprocess.run([graphviz_dot, '-V'], stdout=PIPE, stderr=PIPE) # show version
subprocess.run([graphviz_dot, '-V'], capture_output=True) # show version
return
except OSError: # No such file or directory
pass

View File

@ -88,7 +88,7 @@ def get_full_module_name(node: Node) -> str:
:param nodes.Node node: target node
:return: full module dotted path
"""
return '{}.{}'.format(node.__module__, node.__class__.__name__)
return f'{node.__module__}.{node.__class__.__name__}'
def repr_domxml(node: Node, length: int = 80) -> str:

View File

@ -1528,7 +1528,7 @@ class LaTeXTranslator(SphinxTranslator):
try:
if type == 'single':
try:
p1, p2 = [escape(x) for x in split_into(2, 'single', string)]
p1, p2 = (escape(x) for x in split_into(2, 'single', string))
P1, P2 = style(p1), style(p2)
self.body.append(r'\index{%s@%s!%s@%s%s}' % (p1, P1, p2, P2, m))
except ValueError:
@ -1536,12 +1536,12 @@ class LaTeXTranslator(SphinxTranslator):
P = style(p)
self.body.append(r'\index{%s@%s%s}' % (p, P, m))
elif type == 'pair':
p1, p2 = [escape(x) for x in split_into(2, 'pair', string)]
p1, p2 = (escape(x) for x in split_into(2, 'pair', string))
P1, P2 = style(p1), style(p2)
self.body.append(r'\index{%s@%s!%s@%s%s}\index{%s@%s!%s@%s%s}' %
(p1, P1, p2, P2, m, p2, P2, p1, P1, m))
elif type == 'triple':
p1, p2, p3 = [escape(x) for x in split_into(3, 'triple', string)]
p1, p2, p3 = (escape(x) for x in split_into(3, 'triple', string))
P1, P2, P3 = style(p1), style(p2), style(p3)
self.body.append(
r'\index{%s@%s!%s %s@%s %s%s}'
@ -1551,11 +1551,11 @@ class LaTeXTranslator(SphinxTranslator):
p2, P2, p3, p1, P3, P1, m,
p3, P3, p1, p2, P1, P2, m))
elif type == 'see':
p1, p2 = [escape(x) for x in split_into(2, 'see', string)]
p1, p2 = (escape(x) for x in split_into(2, 'see', string))
P1 = style(p1)
self.body.append(r'\index{%s@%s|see{%s}}' % (p1, P1, p2))
elif type == 'seealso':
p1, p2 = [escape(x) for x in split_into(2, 'seealso', string)]
p1, p2 = (escape(x) for x in split_into(2, 'seealso', string))
P1 = style(p1)
self.body.append(r'\index{%s@%s|see{%s}}' % (p1, P1, p2))
else:

View File

@ -6,10 +6,10 @@ import mod_resource
import mod_something
if __name__ == "__main__":
print("Hello, world! -> something returns: {}".format(mod_something.something()))
print(f"Hello, world! -> something returns: {mod_something.something()}")
res_path = \
os.path.join(os.path.dirname(mod_resource.__file__), 'resource.txt')
with open(res_path, encoding='utf-8') as f:
text = f.read()
print("From mod_resource:resource.txt -> {}".format(text))
print(f"From mod_resource:resource.txt -> {text}")

View File

@ -3,7 +3,7 @@ module with trailing underscores everywhere
"""
class class_(object):
class class_:
""" Class """
def method_(_arg):
""" Method """

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
project = 'Sphinx ChangesBuilder tests'
copyright = '2007-2022 by the Sphinx team, see AUTHORS'
version = '0.6'

View File

@ -1,2 +1 @@
copyright = '2006-2009, Author'

View File

@ -1,3 +1,2 @@
project = 'test-directive-only'
exclude_patterns = ['_build']

View File

@ -1,6 +1,6 @@
from bug2437.autodoc_dummy_foo import Foo
class Bar(object):
class Bar:
"""Dummy class Bar with alias."""
my_name = Foo

View File

@ -1,3 +1,3 @@
class Foo(object):
class Foo:
"""Dummy class Foo."""
pass

View File

@ -33,7 +33,7 @@ def _funky_classmethod(name, b, c, d, docstring=None):
return classmethod(function)
class Class(object):
class Class:
"""Class to document."""
def meth(self):
@ -96,10 +96,10 @@ def function(foo, *args, **kwds):
pass
class Outer(object):
class Outer:
"""Foo"""
class Inner(object):
class Inner:
"""Foo"""
def meth(self):
@ -113,7 +113,7 @@ class InnerChild(Outer.Inner):
"""InnerChild docstring"""
class DocstringSig(object):
class DocstringSig:
def __new__(cls, *new_args, **new_kwargs):
"""__new__(cls, d, e=1) -> DocstringSig
First line of docstring
@ -164,12 +164,12 @@ class StrRepr(str):
return self
class AttCls(object):
class AttCls:
a1 = StrRepr('hello\nworld')
a2 = None
class InstAttCls(object):
class InstAttCls:
"""Class with documented class and instance attributes."""
#: Doc comment for class attribute InstAttCls.ca1.
@ -189,7 +189,7 @@ class InstAttCls(object):
"""Docstring for instance attribute InstAttCls.ia2."""
class CustomIter(object):
class CustomIter:
def __init__(self):
"""Create a new `CustomIter`."""
self.values = range(10)

View File

@ -1,4 +1,4 @@
class CustomDataDescriptor(object):
class CustomDataDescriptor:
"""Descriptor class docstring."""
def __init__(self, doc):

View File

@ -1,4 +1,4 @@
class Base(object):
class Base:
#: docstring
inheritedattr = None

View File

@ -1,4 +1,3 @@
import missing_module
import missing_package1.missing_module1
from missing_module import missing_name
@ -20,7 +19,7 @@ def func(arg: missing_module.Class):
pass
class TestAutodoc(object):
class TestAutodoc:
"""TestAutodoc docstring."""
#: docstring

View File

@ -1,7 +1,7 @@
from functools import partialmethod
class Cell(object):
class Cell:
"""An example for partialmethod.
refs: https://docs.python.jp/3/library/functools.html#functools.partialmethod

View File

@ -8,7 +8,7 @@ attr3 = '' # type: str
class _Descriptor:
def __init__(self, name):
self.__doc__ = "This is {}".format(name)
self.__doc__ = f"This is {name}"
def __get__(self):
pass

View File

@ -1,5 +1,5 @@
# example.sphinx
class DummyClass(object):
class DummyClass:
pass

View File

@ -1,4 +1,4 @@
class Foo(object):
class Foo:
pass

View File

@ -17,13 +17,13 @@ def func1(a, b):
@decorator
class Class1(object):
class Class1:
"""
this is Class1
"""
class Class3(object):
class Class3:
"""
this is Class3
"""

View File

@ -11,7 +11,7 @@ r"""
"""
class A(object):
class A:
pass

View File

@ -2,8 +2,8 @@
"""
class A(object):
class B(object):
class A:
class B:
pass

View File

@ -19,7 +19,7 @@ class CustomEx(Exception):
"""Exception method."""
class CustomDataDescriptor(object):
class CustomDataDescriptor:
"""Descriptor class docstring."""
def __init__(self, doc):
@ -56,7 +56,7 @@ def _funky_classmethod(name, b, c, d, docstring=None):
return classmethod(function)
class Base(object):
class Base:
def inheritedmeth(self):
"""Inherited function."""
@ -136,10 +136,10 @@ def function(foo, *args, **kwds):
pass
class Outer(object):
class Outer:
"""Foo"""
class Inner(object):
class Inner:
"""Foo"""
def meth(self):
@ -149,7 +149,7 @@ class Outer(object):
factory = dict
class DocstringSig(object):
class DocstringSig:
def meth(self):
"""meth(FOO, BAR=1) -> BAZ
First line of docstring
@ -184,12 +184,12 @@ class StrRepr(str):
return self
class AttCls(object):
class AttCls:
a1 = StrRepr('hello\nworld')
a2 = None
class InstAttCls(object):
class InstAttCls:
"""Class with documented class and instance attributes."""
#: Doc comment for class attribute InstAttCls.ca1.

View File

@ -1,5 +1,4 @@
class MarkupError(object):
class MarkupError:
"""
.. note:: This is a docstring with a
small markup error which should have

View File

@ -2,7 +2,7 @@
import os
import subprocess
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
from xml.etree import ElementTree
import pytest
@ -11,7 +11,7 @@ import pytest
# check given command is runnable
def runnable(command):
try:
subprocess.run(command, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(command, capture_output=True, check=True)
return True
except (OSError, CalledProcessError):
return False # command not found or exit with non-zero
@ -377,7 +377,7 @@ def test_run_epubcheck(app):
if runnable(['java', '-version']) and os.path.exists(epubcheck):
try:
subprocess.run(['java', '-jar', epubcheck, app.outdir / 'SphinxTests.epub'],
stdout=PIPE, stderr=PIPE, check=True)
capture_output=True, check=True)
except CalledProcessError as exc:
print(exc.stdout.decode('utf-8'))
print(exc.stderr.decode('utf-8'))

View File

@ -4,7 +4,7 @@ import gettext
import os
import re
import subprocess
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
import pytest
@ -54,7 +54,7 @@ def test_msgfmt(app):
with cd(app.outdir):
try:
args = ['msginit', '--no-translator', '-i', 'markup.pot', '--locale', 'en_US']
subprocess.run(args, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(args, capture_output=True, check=True)
except OSError:
pytest.skip() # most likely msginit was not found
except CalledProcessError as exc:
@ -66,7 +66,7 @@ def test_msgfmt(app):
try:
args = ['msgfmt', 'en_US.po',
'-o', os.path.join('en', 'LC_MESSAGES', 'test_root.mo')]
subprocess.run(args, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(args, capture_output=True, check=True)
except OSError:
pytest.skip() # most likely msgfmt was not found
except CalledProcessError as exc:

View File

@ -105,9 +105,9 @@ def check_xpath(etree, fname, path, check, be_found=True):
if all(not rex.search(get_text(node)) for node in nodes):
return
raise AssertionError(('%r not found in any node matching '
raise AssertionError('%r not found in any node matching '
'path %s in %s: %r' % (check, path, fname,
[node.text for node in nodes])))
[node.text for node in nodes]))
@pytest.mark.sphinx('html', testroot='warnings')

View File

@ -5,7 +5,7 @@ import re
import subprocess
from itertools import product
from shutil import copyfile
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
import pytest
@ -36,7 +36,7 @@ LATEX_WARNINGS = ENV_WARNINGS + """\
# only run latex if all needed packages are there
def kpsetest(*filenames):
try:
subprocess.run(['kpsewhich'] + list(filenames), stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(['kpsewhich'] + list(filenames), capture_output=True, check=True)
return True
except (OSError, CalledProcessError):
return False # command not found or exit with non-zero
@ -55,7 +55,7 @@ def compile_latex_document(app, filename='python.tex'):
'--interaction=nonstopmode',
'-output-directory=%s' % app.config.latex_engine,
filename]
subprocess.run(args, stdout=PIPE, stderr=PIPE, check=True)
subprocess.run(args, capture_output=True, check=True)
except OSError as exc: # most likely the latex executable was not found
raise pytest.skip.Exception from exc
except CalledProcessError as exc:

View File

@ -3,7 +3,7 @@
import os
import re
import subprocess
from subprocess import PIPE, CalledProcessError
from subprocess import CalledProcessError
from unittest.mock import Mock
import pytest
@ -49,7 +49,7 @@ def test_texinfo(app, status, warning):
# now, try to run makeinfo over it
try:
args = ['makeinfo', '--no-split', 'sphinxtests.texi']
subprocess.run(args, stdout=PIPE, stderr=PIPE, cwd=app.outdir, check=True)
subprocess.run(args, capture_output=True, cwd=app.outdir, check=True)
except OSError as exc:
raise pytest.skip.Exception from exc # most likely makeinfo was not found
except CalledProcessError as exc:

View File

@ -470,12 +470,12 @@ def test_domain_c_ast_function_definitions():
cvrs = ['', 'const', 'volatile', 'restrict', 'restrict volatile const']
for cvr in cvrs:
space = ' ' if len(cvr) != 0 else ''
check('function', 'void f(int arr[{}*])'.format(cvr), {1: 'f'})
check('function', 'void f(int arr[{}])'.format(cvr), {1: 'f'})
check('function', 'void f(int arr[{}{}42])'.format(cvr, space), {1: 'f'})
check('function', 'void f(int arr[static{}{} 42])'.format(space, cvr), {1: 'f'})
check('function', 'void f(int arr[{}{}static 42])'.format(cvr, space), {1: 'f'},
output='void f(int arr[static{}{} 42])'.format(space, cvr))
check('function', f'void f(int arr[{cvr}*])', {1: 'f'})
check('function', f'void f(int arr[{cvr}])', {1: 'f'})
check('function', f'void f(int arr[{cvr}{space}42])', {1: 'f'})
check('function', f'void f(int arr[static{space}{cvr} 42])', {1: 'f'})
check('function', f'void f(int arr[{cvr}{space}static 42])', {1: 'f'},
output=f'void f(int arr[static{space}{cvr} 42])')
check('function', 'void f(int arr[const static volatile 42])', {1: 'f'},
output='void f(int arr[static volatile const 42])')
@ -611,9 +611,9 @@ def split_warnigns(warning):
def filter_warnings(warning, file):
lines = split_warnigns(warning)
res = [l for l in lines if "domain-c" in l and "{}.rst".format(file) in l and
res = [l for l in lines if "domain-c" in l and f"{file}.rst" in l and
"WARNING: document isn't included in any toctree" not in l]
print("Filtered warnings for file '{}':".format(file))
print(f"Filtered warnings for file '{file}':")
for w in res:
print(w)
return res
@ -652,7 +652,7 @@ def test_domain_c_build_namespace(app, status, warning):
assert len(ws) == 0
t = (app.outdir / "namespace.html").read_text(encoding='utf8')
for id_ in ('NS.NSVar', 'NULLVar', 'ZeroVar', 'NS2.NS3.NS2NS3Var', 'PopVar'):
assert 'id="c.{}"'.format(id_) in t
assert f'id="c.{id_}"' in t
@pytest.mark.sphinx(testroot='domain-c', confoverrides={'nitpicky': True})

View File

@ -218,7 +218,7 @@ def test_domain_cpp_ast_expressions():
('\\U0001f34c', '127820'), ('\\U0001F34C', '127820')]
for p, t in charPrefixAndIds:
for c, val in chars:
exprCheck("{}'{}'".format(p, c), t + val)
exprCheck(f"{p}'{c}'", t + val)
# user-defined literals
for i in ints:
exprCheck(i + '_udl', 'clL_Zli4_udlEL' + i.replace("'", "") + 'EE')
@ -230,7 +230,7 @@ def test_domain_cpp_ast_expressions():
exprCheck('0x' + f + '_udl', 'clL_Zli4_udlEL0x' + f.replace("'", "") + 'EE')
for p, t in charPrefixAndIds:
for c, val in chars:
exprCheck("{}'{}'_udl".format(p, c), 'clL_Zli4_udlE' + t + val + 'E')
exprCheck(f"{p}'{c}'_udl", 'clL_Zli4_udlE' + t + val + 'E')
exprCheck('"abc"_udl', 'clL_Zli4_udlELA3_KcEE')
# from issue #7294
exprCheck('6.62607015e-34q_J', 'clL_Zli3q_JEL6.62607015e-34EE')
@ -1084,9 +1084,9 @@ def test_domain_cpp_template_parameters_is_pack(param: str, is_pack: bool):
def filter_warnings(warning, file):
lines = warning.getvalue().split("\n")
res = [l for l in lines if "domain-cpp" in l and "{}.rst".format(file) in l and
res = [l for l in lines if "domain-cpp" in l and f"{file}.rst" in l and
"WARNING: document isn't included in any toctree" not in l]
print("Filtered warnings for file '{}':".format(file))
print(f"Filtered warnings for file '{file}':")
for w in res:
print(w)
return res
@ -1169,10 +1169,10 @@ def test_domain_cpp_build_misuse_of_roles(app, status, warning):
txtTargetType = "function" if targetType == "func" else targetType
for r in allRoles:
if r not in roles:
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
warn.append(f"WARNING: cpp:{r} targets a {txtTargetType} (")
if targetType == 'templateParam':
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType))
warn.append(f"WARNING: cpp:{r} targets a {txtTargetType} (")
warn.append(f"WARNING: cpp:{r} targets a {txtTargetType} (")
warn = sorted(warn)
for w in ws:
assert "targets a" in w
@ -1326,7 +1326,7 @@ not found in `{test}`
for role in (expr_role, texpr_role):
name = role.name
expect = '`{name}` puts the domain and role classes at its root'.format(name=name)
expect = f'`{name}` puts the domain and role classes at its root'
assert {'sig', 'sig-inline', 'cpp', name} <= role.classes, expect
# reference classes

View File

@ -318,7 +318,7 @@ def test_toc_all_references_should_exist_pep420_enabled(make_app, apidoc):
if ref and ref[0] in (':', '#'):
continue
found_refs.append(ref)
filename = "{}.rst".format(ref)
filename = f"{ref}.rst"
if not (outdir / filename).isfile():
missing_files.append(filename)
@ -347,7 +347,7 @@ def test_toc_all_references_should_exist_pep420_disabled(make_app, apidoc):
for ref in refs:
if ref and ref[0] in (':', '#'):
continue
filename = "{}.rst".format(ref)
filename = f"{ref}.rst"
found_refs.append(ref)
if not (outdir / filename).isfile():
missing_files.append(filename)

View File

@ -117,7 +117,7 @@ def test_skipif(app, status, warning):
def record(directive, part, should_skip):
global recorded_calls
recorded_calls[(directive, part, should_skip)] += 1
return 'Recorded {} {} {}'.format(directive, part, should_skip)
return f'Recorded {directive} {part} {should_skip}'
@pytest.mark.sphinx('doctest', testroot='ext-doctest-with-autodoc')

View File

@ -1,7 +1,6 @@
"""Test sphinx.ext.imgconverter extension."""
import subprocess
from subprocess import PIPE
import pytest
@ -11,7 +10,7 @@ def if_converter_found(app):
image_converter = getattr(app.config, 'image_converter', '')
try:
if image_converter:
subprocess.run([image_converter, '-version'], stdout=PIPE, stderr=PIPE) # show version
subprocess.run([image_converter, '-version'], capture_output=True) # show version
return
except OSError: # No such file or directory
pass

View File

@ -716,7 +716,7 @@ def test_getdoc_inherited_decorated_method():
"""
class Bar(Foo):
@functools.lru_cache() # noqa: B019
@functools.lru_cache # noqa: B019
def meth(self):
# inherited and decorated method
pass

View File

@ -24,7 +24,7 @@ def stringify_version(version_info, in_develop=True):
def bump_version(path, version_info, in_develop=True):
version = stringify_version(version_info, in_develop)
with open(path, 'r', encoding='utf-8') as f:
with open(path, encoding='utf-8') as f:
lines = f.read().splitlines()
for i, line in enumerate(lines):