Skip to content

Commit 63d2f7f

Browse files
authored
Merge pull request #9248 from bluetech/sphinx4
doc: support sphinx 5
2 parents 739322a + beae7fd commit 63d2f7f

21 files changed

+370
-196
lines changed

doc/en/conf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
autodoc_member_order = "bysource"
4040
autodoc_typehints = "description"
41+
autodoc_typehints_description_target = "documented"
4142
todo_include_todos = 1
4243

4344
latex_engine = "lualatex"
@@ -162,11 +163,11 @@
162163

163164
_repo = "https://github.com/pytest-dev/pytest"
164165
extlinks = {
165-
"bpo": ("https://bugs.python.org/issue%s", "bpo-"),
166-
"pypi": ("https://pypi.org/project/%s/", ""),
167-
"issue": (f"{_repo}/issues/%s", "issue #"),
168-
"pull": (f"{_repo}/pull/%s", "pull request #"),
169-
"user": ("https://github.com/%s", "@"),
166+
"bpo": ("https://bugs.python.org/issue%s", "bpo-%s"),
167+
"pypi": ("https://pypi.org/project/%s/", "%s"),
168+
"issue": (f"{_repo}/issues/%s", "issue #%s"),
169+
"pull": (f"{_repo}/pull/%s", "pull request #%s"),
170+
"user": ("https://github.com/%s", "@%s"),
170171
}
171172

172173

@@ -419,8 +420,6 @@ def filter(self, record: logging.LogRecord) -> bool:
419420

420421

421422
def setup(app: "sphinx.application.Sphinx") -> None:
422-
# from sphinx.ext.autodoc import cut_lines
423-
# app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
424423
app.add_crossref_type(
425424
"fixture",
426425
"fixture",

doc/en/reference/customize.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ and can also be used to hold pytest configuration if they have a ``[pytest]`` se
9090
setup.cfg
9191
~~~~~~~~~
9292

93-
``setup.cfg`` files are general purpose configuration files, used originally by :doc:`distutils <distutils/configfile>`, and can also be used to hold pytest configuration
93+
``setup.cfg`` files are general purpose configuration files, used originally by :doc:`distutils <python:distutils/configfile>`, and can also be used to hold pytest configuration
9494
if they have a ``[tool:pytest]`` section.
9595

9696
.. code-block:: ini

doc/en/reference/reference.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pytest.deprecated_call
102102

103103
**Tutorial**: :ref:`ensuring_function_triggers`
104104

105-
.. autofunction:: pytest.deprecated_call()
105+
.. autofunction:: pytest.deprecated_call([match])
106106
:with:
107107

108108
pytest.register_assert_rewrite
@@ -529,6 +529,7 @@ New code should avoid using :fixture:`testdir` in favor of :fixture:`pytester`.
529529

530530
.. autoclass:: pytest.Testdir()
531531
:members:
532+
:noindex: TimeoutExpired
532533

533534

534535
.. fixture:: recwarn

doc/en/requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ pallets-sphinx-themes
22
pluggy>=1.0
33
pygments-pytest>=2.2.0
44
sphinx-removed-in>=0.2.0
5-
sphinx>=3.1,<4
5+
sphinx>=5,<6
66
sphinxcontrib-trio
77
sphinxcontrib-svg2pdfconverter
8-
9-
# XXX: sphinx<4 is broken with latest jinja2
10-
jinja2<3.1

src/_pytest/assertion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def register_assert_rewrite(*names: str) -> None:
5353
actually imported, usually in your __init__.py if you are a plugin
5454
using a package.
5555
56-
:raises TypeError: If the given module names are not strings.
56+
:param names: The module names to register.
5757
"""
5858
for name in names:
5959
if not isinstance(name, str):

src/_pytest/compat.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
import attr
2121
import py
2222

23+
# fmt: off
24+
# Workaround for https://github.com/sphinx-doc/sphinx/issues/10351.
25+
# If `overload` is imported from `compat` instead of from `typing`,
26+
# Sphinx doesn't recognize it as `overload` and the API docs for
27+
# overloaded functions look good again. But type checkers handle
28+
# it fine.
29+
# fmt: on
30+
if True:
31+
from typing import overload as overload
32+
2333
if TYPE_CHECKING:
2434
from typing_extensions import Final
2535

@@ -345,7 +355,6 @@ def final(f):
345355
if sys.version_info >= (3, 8):
346356
from functools import cached_property as cached_property
347357
else:
348-
from typing import overload
349358
from typing import Type
350359

351360
class cached_property(Generic[_S, _T]):

src/_pytest/config/argparsing.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ def getgroup(
6666
) -> "OptionGroup":
6767
"""Get (or create) a named option Group.
6868
69-
:name: Name of the option group.
70-
:description: Long description for --help output.
71-
:after: Name of another group, used for ordering --help output.
69+
:param name: Name of the option group.
70+
:param description: Long description for --help output.
71+
:param after: Name of another group, used for ordering --help output.
72+
:returns: The option group.
7273
7374
The returned group object has an ``addoption`` method with the same
7475
signature as :func:`parser.addoption <pytest.Parser.addoption>` but
7576
will be shown in the respective group in the output of
76-
``pytest. --help``.
77+
``pytest --help``.
7778
"""
7879
for group in self._groups:
7980
if group.name == name:
@@ -89,10 +90,11 @@ def getgroup(
8990
def addoption(self, *opts: str, **attrs: Any) -> None:
9091
"""Register a command line option.
9192
92-
:opts: Option names, can be short or long options.
93-
:attrs: Same attributes which the ``add_argument()`` function of the
94-
`argparse library <https://docs.python.org/library/argparse.html>`_
95-
accepts.
93+
:param opts:
94+
Option names, can be short or long options.
95+
:param attrs:
96+
Same attributes as the argparse library's :py:func:`add_argument()
97+
<argparse.ArgumentParser.add_argument>` function accepts.
9698
9799
After command line parsing, options are available on the pytest config
98100
object via ``config.option.NAME`` where ``NAME`` is usually set
@@ -148,16 +150,24 @@ def parse_known_args(
148150
args: Sequence[Union[str, "os.PathLike[str]"]],
149151
namespace: Optional[argparse.Namespace] = None,
150152
) -> argparse.Namespace:
151-
"""Parse and return a namespace object with known arguments at this point."""
153+
"""Parse the known arguments at this point.
154+
155+
:returns: An argparse namespace object.
156+
"""
152157
return self.parse_known_and_unknown_args(args, namespace=namespace)[0]
153158

154159
def parse_known_and_unknown_args(
155160
self,
156161
args: Sequence[Union[str, "os.PathLike[str]"]],
157162
namespace: Optional[argparse.Namespace] = None,
158163
) -> Tuple[argparse.Namespace, List[str]]:
159-
"""Parse and return a namespace object with known arguments, and
160-
the remaining arguments unknown at this point."""
164+
"""Parse the known arguments at this point, and also return the
165+
remaining unknown arguments.
166+
167+
:returns:
168+
A tuple containing an argparse namespace object for the known
169+
arguments, and a list of the unknown arguments.
170+
"""
161171
optparser = self._getparser()
162172
strargs = [os.fspath(x) for x in args]
163173
return optparser.parse_known_args(strargs, namespace=namespace)
@@ -173,9 +183,9 @@ def addini(
173183
) -> None:
174184
"""Register an ini-file option.
175185
176-
:name:
186+
:param name:
177187
Name of the ini-variable.
178-
:type:
188+
:param type:
179189
Type of the variable. Can be:
180190
181191
* ``string``: a string
@@ -189,7 +199,7 @@ def addini(
189199
The ``paths`` variable type.
190200
191201
Defaults to ``string`` if ``None`` or not passed.
192-
:default:
202+
:param default:
193203
Default value if no ini-file option exists but is queried.
194204
195205
The value of ini-variables can be retrieved via a call to
@@ -354,24 +364,30 @@ def __init__(
354364
self.options: List[Argument] = []
355365
self.parser = parser
356366

357-
def addoption(self, *optnames: str, **attrs: Any) -> None:
367+
def addoption(self, *opts: str, **attrs: Any) -> None:
358368
"""Add an option to this group.
359369
360370
If a shortened version of a long option is specified, it will
361371
be suppressed in the help. ``addoption('--twowords', '--two-words')``
362372
results in help showing ``--two-words`` only, but ``--twowords`` gets
363373
accepted **and** the automatic destination is in ``args.twowords``.
374+
375+
:param opts:
376+
Option names, can be short or long options.
377+
:param attrs:
378+
Same attributes as the argparse library's :py:func:`add_argument()
379+
<argparse.ArgumentParser.add_argument>` function accepts.
364380
"""
365-
conflict = set(optnames).intersection(
381+
conflict = set(opts).intersection(
366382
name for opt in self.options for name in opt.names()
367383
)
368384
if conflict:
369385
raise ValueError("option names %s already added" % conflict)
370-
option = Argument(*optnames, **attrs)
386+
option = Argument(*opts, **attrs)
371387
self._addoption_instance(option, shortupper=False)
372388

373-
def _addoption(self, *optnames: str, **attrs: Any) -> None:
374-
option = Argument(*optnames, **attrs)
389+
def _addoption(self, *opts: str, **attrs: Any) -> None:
390+
option = Argument(*opts, **attrs)
375391
self._addoption_instance(option, shortupper=True)
376392

377393
def _addoption_instance(self, option: "Argument", shortupper: bool = False) -> None:

src/_pytest/fixtures.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from typing import MutableMapping
2121
from typing import NoReturn
2222
from typing import Optional
23-
from typing import overload
2423
from typing import Sequence
2524
from typing import Set
2625
from typing import Tuple
@@ -48,6 +47,7 @@
4847
from _pytest.compat import getlocation
4948
from _pytest.compat import is_generator
5049
from _pytest.compat import NOTSET
50+
from _pytest.compat import overload
5151
from _pytest.compat import safe_getattr
5252
from _pytest.config import _PluggyPlugin
5353
from _pytest.config import Config
@@ -513,8 +513,8 @@ def session(self) -> "Session":
513513
return self._pyfuncitem.session # type: ignore[no-any-return]
514514

515515
def addfinalizer(self, finalizer: Callable[[], object]) -> None:
516-
"""Add finalizer/teardown function to be called after the last test
517-
within the requesting test context finished execution."""
516+
"""Add finalizer/teardown function to be called without arguments after
517+
the last test within the requesting test context finished execution."""
518518
# XXX usually this method is shadowed by fixturedef specific ones.
519519
self._addfinalizer(finalizer, scope=self.scope)
520520

@@ -529,13 +529,16 @@ def applymarker(self, marker: Union[str, MarkDecorator]) -> None:
529529
on all function invocations.
530530
531531
:param marker:
532-
A :class:`pytest.MarkDecorator` object created by a call
533-
to ``pytest.mark.NAME(...)``.
532+
An object created by a call to ``pytest.mark.NAME(...)``.
534533
"""
535534
self.node.add_marker(marker)
536535

537536
def raiseerror(self, msg: Optional[str]) -> NoReturn:
538-
"""Raise a FixtureLookupError with the given message."""
537+
"""Raise a FixtureLookupError exception.
538+
539+
:param msg:
540+
An optional custom error message.
541+
"""
539542
raise self._fixturemanager.FixtureLookupError(None, self, msg)
540543

541544
def _fillfixtures(self) -> None:
@@ -557,6 +560,8 @@ def getfixturevalue(self, argname: str) -> Any:
557560
phase, but during the test teardown phase a fixture's value may not
558561
be available.
559562
563+
:param argname:
564+
The fixture name.
560565
:raises pytest.FixtureLookupError:
561566
If the given fixture could not be found.
562567
"""
@@ -768,8 +773,8 @@ def __repr__(self) -> str:
768773
return f"<SubRequest {self.fixturename!r} for {self._pyfuncitem!r}>"
769774

770775
def addfinalizer(self, finalizer: Callable[[], object]) -> None:
771-
"""Add finalizer/teardown function to be called after the last test
772-
within the requesting test context finished execution."""
776+
"""Add finalizer/teardown function to be called without arguments after
777+
the last test within the requesting test context finished execution."""
773778
self._fixturedef.addfinalizer(finalizer)
774779

775780
def _schedule_finalizers(
@@ -1226,7 +1231,7 @@ def fixture(
12261231

12271232

12281233
@overload
1229-
def fixture(
1234+
def fixture( # noqa: F811
12301235
fixture_function: None = ...,
12311236
*,
12321237
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = ...,
@@ -1240,7 +1245,7 @@ def fixture(
12401245
...
12411246

12421247

1243-
def fixture(
1248+
def fixture( # noqa: F811
12441249
fixture_function: Optional[FixtureFunction] = None,
12451250
*,
12461251
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = "function",

0 commit comments

Comments
 (0)