mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Run pyupgrade (#11070)
This commit is contained in:
@@ -7,4 +7,4 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class Foo:
|
||||
attr1: "StringIO"
|
||||
attr1: StringIO
|
||||
|
||||
@@ -9,7 +9,7 @@ def sum(x: int, y: int = 0) -> int:
|
||||
|
||||
|
||||
@overload
|
||||
def sum(x: "float", y: "float" = 0.0) -> "float":
|
||||
def sum(x: float, y: float = 0.0) -> float:
|
||||
...
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Math:
|
||||
...
|
||||
|
||||
@overload
|
||||
def sum(self, x: "float", y: "float" = 0.0) -> "float":
|
||||
def sum(self, x: float, y: float = 0.0) -> float:
|
||||
...
|
||||
|
||||
@overload
|
||||
@@ -47,11 +47,11 @@ class Foo:
|
||||
"""docstring"""
|
||||
|
||||
@overload
|
||||
def __new__(cls, x: int, y: int) -> "Foo":
|
||||
def __new__(cls, x: int, y: int) -> Foo:
|
||||
...
|
||||
|
||||
@overload
|
||||
def __new__(cls, x: "str", y: "str") -> "Foo":
|
||||
def __new__(cls, x: str, y: str) -> Foo:
|
||||
...
|
||||
|
||||
def __new__(cls, x, y):
|
||||
@@ -66,7 +66,7 @@ class Bar:
|
||||
...
|
||||
|
||||
@overload
|
||||
def __init__(cls, x: "str", y: "str") -> "None":
|
||||
def __init__(cls, x: str, y: str) -> None:
|
||||
...
|
||||
|
||||
def __init__(cls, x, y):
|
||||
@@ -79,7 +79,7 @@ class Meta(type):
|
||||
...
|
||||
|
||||
@overload
|
||||
def __call__(cls, x: "str", y: "str") -> "Any":
|
||||
def __call__(cls, x: str, y: str) -> Any:
|
||||
...
|
||||
|
||||
def __call__(cls, x, y):
|
||||
|
||||
@@ -56,12 +56,12 @@ class Math:
|
||||
return pathlib.PurePosixPath("/a/b/c")
|
||||
|
||||
|
||||
def tuple_args(x: Tuple[int, Union[int, str]]) -> Tuple[int, int]:
|
||||
def tuple_args(x: tuple[int, int | str]) -> tuple[int, int]:
|
||||
pass
|
||||
|
||||
|
||||
class NewAnnotation:
|
||||
def __new__(cls, i: int) -> 'NewAnnotation':
|
||||
def __new__(cls, i: int) -> NewAnnotation:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -19,5 +19,5 @@ class Foo:
|
||||
pass
|
||||
|
||||
|
||||
def bar(x: Union[int, str], y: int = 1) -> None:
|
||||
def bar(x: int | str, y: int = 1) -> None:
|
||||
pass
|
||||
|
||||
@@ -19,6 +19,6 @@ if 'test_linkcode' in tags:
|
||||
elif domain == "js":
|
||||
return "http://foobar/js/" + info['fullname']
|
||||
elif domain in ("c", "cpp"):
|
||||
return "http://foobar/%s/%s" % (domain, "".join(info['names']))
|
||||
return f"http://foobar/{domain}/{''.join(info['names'])}"
|
||||
else:
|
||||
raise AssertionError()
|
||||
|
||||
@@ -16,13 +16,13 @@ def func1(a, b):
|
||||
|
||||
|
||||
@decorator
|
||||
class Class1(object):
|
||||
class Class1:
|
||||
"""
|
||||
this is Class1
|
||||
"""
|
||||
|
||||
|
||||
class Class3(object):
|
||||
class Class3:
|
||||
"""
|
||||
this is Class3
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ def func2(a, b):
|
||||
|
||||
|
||||
@decorator
|
||||
class Class2(object):
|
||||
class Class2:
|
||||
"""
|
||||
this is Class2
|
||||
"""
|
||||
|
||||
@@ -70,7 +70,7 @@ def tail_check(check):
|
||||
for node in nodes:
|
||||
if node.tail and rex.search(node.tail):
|
||||
return True
|
||||
raise AssertionError('%r not found in tail of any nodes %s' % (check, nodes))
|
||||
raise AssertionError(f'{check!r} not found in tail of any nodes {nodes}')
|
||||
return checker
|
||||
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ def compile_latex_document(app, filename='python.tex'):
|
||||
except CalledProcessError as exc:
|
||||
print(exc.stdout.decode('utf8'))
|
||||
print(exc.stderr.decode('utf8'))
|
||||
raise AssertionError('%s exited with return code %s' % (app.config.latex_engine,
|
||||
exc.returncode))
|
||||
raise AssertionError(f'{app.config.latex_engine} exited with '
|
||||
f'return code {exc.returncode}')
|
||||
|
||||
|
||||
def skip_if_requested(testfunc):
|
||||
|
||||
@@ -1199,7 +1199,7 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, war
|
||||
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
|
||||
res = re.search(pattern, text)
|
||||
if not res:
|
||||
print("Pattern\n\t%s\nnot found in %s" % (pattern, file))
|
||||
print(f"Pattern\n\t{pattern}\nnot found in {file}")
|
||||
raise AssertionError()
|
||||
rolePatterns = [
|
||||
('', 'Sphinx'),
|
||||
@@ -1240,7 +1240,7 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, wa
|
||||
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
|
||||
res = re.search(pattern, text)
|
||||
if not res:
|
||||
print("Pattern\n\t%s\nnot found in %s" % (pattern, file))
|
||||
print(f"Pattern\n\t{pattern}\nnot found in {file}")
|
||||
raise AssertionError()
|
||||
rolePatterns = [
|
||||
('', 'Sphinx'),
|
||||
@@ -1281,16 +1281,16 @@ def test_domain_cpp_build_xref_consistency(app, status, warning):
|
||||
output = (app.outdir / test).read_text(encoding='utf8')
|
||||
|
||||
def classes(role, tag):
|
||||
pattern = (r'{role}-role:.*?'
|
||||
r'<(?P<tag>{tag}) .*?class=["\'](?P<classes>.*?)["\'].*?>'
|
||||
pattern = (fr'{role}-role:.*?'
|
||||
fr'<(?P<tag>{tag}) .*?class=["\'](?P<classes>.*?)["\'].*?>'
|
||||
r'.*'
|
||||
r'</(?P=tag)>').format(role=role, tag=tag)
|
||||
r'</(?P=tag)>')
|
||||
result = re.search(pattern, output)
|
||||
expect = '''\
|
||||
expect = f'''\
|
||||
Pattern for role `{role}` with tag `{tag}`
|
||||
\t{pattern}
|
||||
not found in `{test}`
|
||||
'''.format(role=role, tag=tag, pattern=pattern, test=test)
|
||||
'''
|
||||
assert result, expect
|
||||
return set(result.group('classes').split())
|
||||
|
||||
|
||||
@@ -779,8 +779,7 @@ def test_autodoc_typehints_signature(app):
|
||||
' :module: target.typehints',
|
||||
'',
|
||||
'',
|
||||
'.. py:function:: tuple_args(x: ~typing.Tuple[int, ~typing.Union[int, str]]) '
|
||||
'-> ~typing.Tuple[int, int]',
|
||||
'.. py:function:: tuple_args(x: tuple[int, int | str]) -> tuple[int, int]',
|
||||
' :module: target.typehints',
|
||||
'',
|
||||
]
|
||||
@@ -965,10 +964,10 @@ def test_autodoc_typehints_description(app):
|
||||
assert ('target.typehints.tuple_args(x)\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
|
||||
' **x** (*tuple**[**int**, **int** | **str**]*) --\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
' tuple[int, int]\n'
|
||||
in context)
|
||||
|
||||
# Overloads still get displayed in the signature
|
||||
@@ -1015,13 +1014,13 @@ def test_autodoc_typehints_description_no_undoc(app):
|
||||
'target.typehints.tuple_args(x)\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) -- arg\n'
|
||||
' **x** (*tuple**[**int**, **int** | **str**]*) -- arg\n'
|
||||
'\n'
|
||||
' Returns:\n'
|
||||
' another tuple\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
' tuple[int, int]\n'
|
||||
in context)
|
||||
|
||||
|
||||
@@ -1072,13 +1071,13 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
|
||||
'target.typehints.tuple_args(x)\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) -- arg\n'
|
||||
' **x** (*tuple**[**int**, **int** | **str**]*) -- arg\n'
|
||||
'\n'
|
||||
' Returns:\n'
|
||||
' another tuple\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
' tuple[int, int]\n'
|
||||
'\n'
|
||||
'target.typehints.Math.nothing(self)\n'
|
||||
'\n'
|
||||
@@ -1221,13 +1220,13 @@ def test_autodoc_typehints_both(app):
|
||||
' Return type:\n'
|
||||
' int\n'
|
||||
in context)
|
||||
assert ('target.typehints.tuple_args(x: Tuple[int, Union[int, str]]) -> Tuple[int, int]\n'
|
||||
assert ('target.typehints.tuple_args(x: tuple[int, int | str]) -> tuple[int, int]\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
|
||||
' **x** (*tuple**[**int**, **int** | **str**]*) --\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
' tuple[int, int]\n'
|
||||
in context)
|
||||
|
||||
# Overloads still get displayed in the signature
|
||||
@@ -1527,8 +1526,7 @@ def test_autodoc_typehints_format_fully_qualified(app):
|
||||
' :module: target.typehints',
|
||||
'',
|
||||
'',
|
||||
'.. py:function:: tuple_args(x: typing.Tuple[int, typing.Union[int, str]]) '
|
||||
'-> typing.Tuple[int, int]',
|
||||
'.. py:function:: tuple_args(x: tuple[int, int | str]) -> tuple[int, int]',
|
||||
' :module: target.typehints',
|
||||
'',
|
||||
]
|
||||
|
||||
@@ -62,7 +62,7 @@ def test_mangle_signature():
|
||||
if '::' in x]
|
||||
for inp, outp in TEST:
|
||||
res = mangle_signature(inp).strip().replace("\u00a0", " ")
|
||||
assert res == outp, ("'%s' -> '%s' != '%s'" % (inp, res, outp))
|
||||
assert res == outp, (f"'{inp}' -> '{res}' != '{outp}'")
|
||||
|
||||
|
||||
def test_extract_summary(capsys):
|
||||
|
||||
@@ -410,25 +410,24 @@ class GoogleDocstringTest(BaseDocstringTest):
|
||||
config = Config()
|
||||
for section, admonition in admonition_map.items():
|
||||
# Multiline
|
||||
actual = str(GoogleDocstring(("{}:\n"
|
||||
" this is the first line\n"
|
||||
"\n"
|
||||
" and this is the second line\n"
|
||||
).format(section), config))
|
||||
expect = (".. {}::\n"
|
||||
actual = str(GoogleDocstring(f"{section}:\n"
|
||||
" this is the first line\n"
|
||||
"\n"
|
||||
" and this is the second line\n",
|
||||
config))
|
||||
expect = (f".. {admonition}::\n"
|
||||
"\n"
|
||||
" this is the first line\n"
|
||||
" \n"
|
||||
" and this is the second line\n"
|
||||
).format(admonition)
|
||||
)
|
||||
self.assertEqual(expect, actual)
|
||||
|
||||
# Single line
|
||||
actual = str(GoogleDocstring(("{}:\n"
|
||||
" this is a single line\n"
|
||||
).format(section), config))
|
||||
expect = (".. {}:: this is a single line\n"
|
||||
).format(admonition)
|
||||
actual = str(GoogleDocstring(f"{section}:\n"
|
||||
" this is a single line\n",
|
||||
config))
|
||||
expect = f".. {admonition}:: this is a single line\n"
|
||||
self.assertEqual(expect, actual)
|
||||
|
||||
def test_docstrings(self):
|
||||
@@ -1472,27 +1471,26 @@ class NumpyDocstringTest(BaseDocstringTest):
|
||||
config = Config()
|
||||
for section, admonition in admonition_map.items():
|
||||
# Multiline
|
||||
actual = str(NumpyDocstring(("{}\n"
|
||||
"{}\n"
|
||||
" this is the first line\n"
|
||||
"\n"
|
||||
" and this is the second line\n"
|
||||
).format(section, '-' * len(section)), config))
|
||||
expect = (".. {}::\n"
|
||||
actual = str(NumpyDocstring(f"{section}\n"
|
||||
f"{'-' * len(section)}\n"
|
||||
" this is the first line\n"
|
||||
"\n"
|
||||
" and this is the second line\n",
|
||||
config))
|
||||
expect = (f".. {admonition}::\n"
|
||||
"\n"
|
||||
" this is the first line\n"
|
||||
" \n"
|
||||
" and this is the second line\n"
|
||||
).format(admonition)
|
||||
)
|
||||
self.assertEqual(expect, actual)
|
||||
|
||||
# Single line
|
||||
actual = str(NumpyDocstring(("{}\n"
|
||||
"{}\n"
|
||||
" this is a single line\n"
|
||||
).format(section, '-' * len(section)), config))
|
||||
expect = (".. {}:: this is a single line\n"
|
||||
).format(admonition)
|
||||
actual = str(NumpyDocstring(f"{section}\n"
|
||||
f"{'-' * len(section)}\n"
|
||||
f" this is a single line\n",
|
||||
config))
|
||||
expect = f".. {admonition}:: this is a single line\n"
|
||||
self.assertEqual(expect, actual)
|
||||
|
||||
def test_docstrings(self):
|
||||
|
||||
@@ -36,8 +36,7 @@ def test_viewcode(app, status, warning):
|
||||
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
|
||||
'href="../../index.html#spam.Class1">[docs]</a>'
|
||||
'<span>@decorator</span>\n'
|
||||
'<span>class</span> <span>Class1</span>'
|
||||
'<span>(</span><span>object</span><span>):</span>\n'
|
||||
'<span>class</span> <span>Class1</span><span>:</span>\n'
|
||||
'<span> </span><span>"""</span>\n'
|
||||
'<span> this is Class1</span>\n'
|
||||
'<span> """</span></div>\n') in result
|
||||
@@ -45,8 +44,7 @@ def test_viewcode(app, status, warning):
|
||||
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
|
||||
'href="../../index.html#spam.Class1">[docs]</a>'
|
||||
'<span>@decorator</span>\n'
|
||||
'<span>class</span> <span>Class1</span>'
|
||||
'<span>(</span><span>object</span><span>):</span>\n'
|
||||
'<span>class</span> <span>Class1</span><span>:</span>\n'
|
||||
' <span>"""</span>\n'
|
||||
'<span> this is Class1</span>\n'
|
||||
'<span> """</span></div>\n') in result
|
||||
|
||||
@@ -705,12 +705,12 @@ def test_html_index_entries(app):
|
||||
def wrap(tag, keyword):
|
||||
start_tag = "<%s[^>]*>" % tag
|
||||
end_tag = "</%s>" % tag
|
||||
return r"%s\s*%s\s*%s" % (start_tag, keyword, end_tag)
|
||||
return fr"{start_tag}\s*{keyword}\s*{end_tag}"
|
||||
|
||||
def wrap_nest(parenttag, childtag, keyword):
|
||||
start_tag1 = "<%s[^>]*>" % parenttag
|
||||
start_tag2 = "<%s[^>]*>" % childtag
|
||||
return r"%s\s*%s\s*%s" % (start_tag1, keyword, start_tag2)
|
||||
return fr"{start_tag1}\s*{keyword}\s*{start_tag2}"
|
||||
expected_exprs = [
|
||||
wrap('a', 'NEWSLETTER'),
|
||||
wrap('a', 'MAILING LIST'),
|
||||
|
||||
Reference in New Issue
Block a user