Skip to content
1 change: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ ignore = [
"TRY300", # Consider moving this statement to an `else` block
# pyupgrade
"UP031", # Use format specifiers instead of percent format
"UP032", # Use f-string instead of `format` call
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieleades I think this works well, but it's not really related to Python 3.12 - either we should put it into a separate PR, or alter the description of this one to be more generic.

# Ruff-specific rules ('RUF')
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF021", # Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/autodoc/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def import_object(
exc = exc_on_importing

if objpath:
errmsg = 'autodoc: failed to import %s %r from module %r' % (
errmsg = 'autodoc: failed to import {} {!r} from module {!r}'.format(
objtype,
'.'.join(objpath),
modname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
variable2 = None # type: myint

#: docstring
variable3: Optional[myint] # NoQA: UP045
variable3: myint | None


def read(r: io.BytesIO) -> io.StringIO:
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autodoc/target/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, x, y):
pass


class Quux(List[Union[int, float]]): # NoQA: UP006,UP007
class Quux(list[Union[int, float]]): # NoQA: UP007, FURB189
"""A subclass of List[Union[int, float]]"""

pass
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autodoc/target/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import typing
from typing import final
from typing import final as final_ext

import typing_extensions
from typing_extensions import final as final_ext # noqa: UP035


@typing.final
Expand Down
9 changes: 5 additions & 4 deletions tests/roots/test-ext-autodoc/target/genericalias.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from __future__ import annotations

from typing import Callable, List
from collections.abc import Callable
from typing import List

#: A list of int
T = List[int]
T = list[int]

C = Callable[[int], None] # a generic alias not having a doccomment


class Class:
#: A list of int
T = List[int]
T = list[int]


#: A list of Class
L = List[Class]
L = list[Class]
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autodoc/target/overload3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typing
from typing import TYPE_CHECKING, overload
from typing import overload as over_ext

import typing_extensions
from typing_extensions import overload as over_ext # noqa: UP035


@overload
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autodoc/target/wrappedfunction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

from collections.abc import Generator # noqa: TC003
from contextlib import contextmanager
from functools import lru_cache
from typing import Generator # NoQA: TC003,UP035


@lru_cache(maxsize=None) # NoQA: UP033
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _Baz:
pass


def bar(x: Union[int, str], y: int = 1) -> None: # NoQA: UP007
def bar(x: int | str, y: int = 1) -> None:
pass


Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-inheritance_diagram/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class DocMainLevel(Foo):
pass


class Alice(object): # NoQA: UP004
class Alice:
pass
2 changes: 1 addition & 1 deletion tests/roots/test-ext-viewcode-find-package/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def linkcode_resolve(domain, info):
elif domain == 'js':
return 'http://foobar/js/' + info['fullname']
elif domain in {'c', 'cpp'}:
return 'http://foobar/%s/%s' % (domain, ''.join(info['names']))
return 'http://foobar/{}/{}'.format(domain, ''.join(info['names']))
else:
raise AssertionError
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

30 changes: 10 additions & 20 deletions tests/test_domains/test_domain_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,15 @@ def test_domain_js_javascript_maximum_signature_line_length_in_html(app):
)
assert expected_f in content

expected_parameter_list_foo = """\
expected_parameter_list_foo = f"""\

<dl>
{}{}{}{}{}{}</dl>
{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f}</dl>

<span class="sig-paren">)</span>\
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
</dt>\
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
"""
assert expected_parameter_list_foo in content


Expand Down Expand Up @@ -799,13 +799,8 @@ def test_domain_js_javascript_maximum_signature_line_length_in_text(app):
expected_f = param_line_fmt.format('f,]')
assert expected_f in content

expected_parameter_list_foo = '(\n{}{}{}{}{}{})'.format(
expected_a,
expected_b,
expected_c,
expected_d,
expected_e,
expected_f,
expected_parameter_list_foo = (
f'(\n{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f})'
)
assert expected_parameter_list_foo in content

Expand Down Expand Up @@ -872,15 +867,15 @@ def test_domain_js_javascript_trailing_comma_in_multi_line_signatures_in_html(ap
)
assert expected_f in content

expected_parameter_list_foo = """\
expected_parameter_list_foo = f"""\

<dl>
{}{}{}{}{}{}</dl>
{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f}</dl>

<span class="sig-paren">)</span>\
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
</dt>\
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
"""
assert expected_parameter_list_foo in content


Expand Down Expand Up @@ -917,13 +912,8 @@ def test_domain_js_javascript_trailing_comma_in_multi_line_signatures_in_text(ap
expected_f = param_line_fmt.format('f]')
assert expected_f in content

expected_parameter_list_foo = '(\n{}{}{}{}{}{})'.format(
expected_a,
expected_b,
expected_c,
expected_d,
expected_e,
expected_f,
expected_parameter_list_foo = (
f'(\n{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f})'
)
assert expected_parameter_list_foo in content

Expand Down
30 changes: 10 additions & 20 deletions tests/test_domains/test_domain_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,15 +1065,15 @@ def test_domain_py_python_maximum_signature_line_length_in_html(app):
)
assert expected_f in content

expected_parameter_list_foo = """\
expected_parameter_list_foo = f"""\

<dl>
{}{}{}{}{}{}</dl>
{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f}</dl>

<span class="sig-paren">)</span>\
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
</dt>\
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
"""
assert expected_parameter_list_foo in content


Expand Down Expand Up @@ -1110,13 +1110,8 @@ def test_domain_py_python_maximum_signature_line_length_in_text(app):
expected_f = param_line_fmt.format('f,]')
assert expected_f in content

expected_parameter_list_foo = '(\n{}{}{}{}{}{})'.format(
expected_a,
expected_b,
expected_c,
expected_d,
expected_e,
expected_f,
expected_parameter_list_foo = (
f'(\n{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f})'
)
assert expected_parameter_list_foo in content

Expand Down Expand Up @@ -1190,15 +1185,15 @@ def test_domain_py_python_trailing_comma_in_multi_line_signatures_in_html(app):
)
assert expected_f in content

expected_parameter_list_foo = """\
expected_parameter_list_foo = f"""\

<dl>
{}{}{}{}{}{}</dl>
{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f}</dl>

<span class="sig-paren">)</span>\
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
</dt>\
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
"""
assert expected_parameter_list_foo in content


Expand Down Expand Up @@ -1237,13 +1232,8 @@ def test_domain_py_python_trailing_comma_in_multi_line_signatures_in_text(app):
expected_f = param_line_fmt.format('f]')
assert expected_f in content

expected_parameter_list_foo = '(\n{}{}{}{}{}{})'.format(
expected_a,
expected_b,
expected_c,
expected_d,
expected_e,
expected_f,
expected_parameter_list_foo = (
f'(\n{expected_a}{expected_b}{expected_c}{expected_d}{expected_e}{expected_f})'
)
assert expected_parameter_list_foo in content

Expand Down
7 changes: 3 additions & 4 deletions tests/test_ext_autodoc/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,24 +2182,23 @@ def test_autodoc_GenericAlias() -> None:
'',
' A list of int',
'',
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
' alias of :py:class:`list`\\ [:py:class:`int`]',
'',
'',
'.. py:data:: L',
' :module: target.genericalias',
'',
' A list of Class',
'',
' alias of :py:class:`~typing.List`\\ '
'[:py:class:`~target.genericalias.Class`]',
' alias of :py:class:`list`\\ [:py:class:`~target.genericalias.Class`]',
'',
'',
'.. py:data:: T',
' :module: target.genericalias',
'',
' A list of int',
'',
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
' alias of :py:class:`list`\\ [:py:class:`int`]',
'',
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_autodoc/test_ext_autodoc_autoattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_autoattribute_GenericAlias() -> None:
'',
' A list of int',
'',
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
' alias of :py:class:`list`\\ [:py:class:`int`]',
'',
]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ext_autodoc/test_ext_autodoc_autoclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_show_inheritance_for_subclass_of_generic_type() -> None:
'.. py:class:: Quux(iterable=(), /)',
' :module: target.classes',
'',
' Bases: :py:class:`~typing.List`\\ [:py:class:`int` | :py:class:`float`]',
' Bases: :py:class:`list`\\ [:py:class:`int` | :py:class:`float`]',
'',
' A subclass of List[Union[int, float]]',
'',
Expand All @@ -324,7 +324,7 @@ def _autodoc_process_bases(
assert obj.__module__ == 'target.classes'
assert obj.__name__ == 'Quux'
assert vars(options) == {}
assert bases == [typing.List[typing.Union[int, float]]] # NoQA: UP006, UP007
assert bases == [list[typing.Union[int, float]]] # noqa: UP007

bases.pop()
bases.extend([int, str])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_autodoc/test_ext_autodoc_autodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_autodata_GenericAlias() -> None:
'',
' A list of int',
'',
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
' alias of :py:class:`list`\\ [:py:class:`int`]',
'',
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_autodoc/test_ext_autodoc_autofunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_wrapped_function_contextmanager() -> None:
actual = do_autodoc('function', 'target.wrappedfunction.feeling_good')
assert actual == [
'',
'.. py:function:: feeling_good(x: int, y: int) -> ~typing.Generator',
'.. py:function:: feeling_good(x: int, y: int) -> ~collections.abc.Generator',
' :module: target.wrappedfunction',
'',
" You'll feel better in this context!",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_autodoc/test_ext_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def test_autodoc_typehints_format_fully_qualified_for_generic_alias() -> None:
'',
' A list of Class',
'',
' alias of :py:class:`~typing.List`\\ [:py:class:`target.genericalias.Class`]',
' alias of :py:class:`list`\\ [:py:class:`target.genericalias.Class`]',
'',
]

Expand Down
Loading
Loading