Skip to content

Commit cf4ae25

Browse files
resolve most sphinx lookup errors
1 parent 18ab1b1 commit cf4ae25

File tree

7 files changed

+53
-37
lines changed

7 files changed

+53
-37
lines changed

doc/en/conf.py

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
autodoc_member_order = "bysource"
4141
autodoc_typehints = "description"
4242
autodoc_typehints_description_target = "documented"
43+
44+
45+
autodoc2_packages = ["pytest", "_pytest"]
4346
todo_include_todos = 1
4447

4548
latex_engine = "lualatex"
@@ -180,6 +183,7 @@
180183
("py:class", "SubRequest"),
181184
("py:class", "TerminalReporter"),
182185
("py:class", "_pytest._code.code.TerminalRepr"),
186+
("py:class", "TerminalRepr"),
183187
("py:class", "_pytest.fixtures.FixtureFunctionMarker"),
184188
("py:class", "_pytest.logging.LogCaptureHandler"),
185189
("py:class", "_pytest.mark.structures.ParameterSet"),
@@ -201,13 +205,16 @@
201205
("py:class", "_PluggyPlugin"),
202206
# TypeVars
203207
("py:class", "_pytest._code.code.E"),
208+
("py:class", "E"), # due to delayed annotation
204209
("py:class", "_pytest.fixtures.FixtureFunction"),
205210
("py:class", "_pytest.nodes._NodeType"),
211+
("py:class", "_NodeType"), # due to delayed annotation
206212
("py:class", "_pytest.python_api.E"),
207213
("py:class", "_pytest.recwarn.T"),
208214
("py:class", "_pytest.runner.TResult"),
209215
("py:obj", "_pytest.fixtures.FixtureValue"),
210216
("py:obj", "_pytest.stash.T"),
217+
("py:class", "_ScopeName"),
211218
]
212219

213220

src/_pytest/_code/code.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ def getrepr(
622622
showlocals: bool = False,
623623
style: TracebackStyle = "long",
624624
abspath: bool = False,
625-
tbfilter: bool | Callable[[ExceptionInfo[BaseException]], Traceback] = True,
625+
tbfilter: bool
626+
| Callable[[ExceptionInfo[BaseException]], _pytest._code.code.Traceback] = True,
626627
funcargs: bool = False,
627628
truncate_locals: bool = True,
628629
truncate_args: bool = True,

src/_pytest/config/__init__.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import importlib.metadata
1414
import inspect
1515
import os
16-
from pathlib import Path
16+
import pathlib
1717
import re
1818
import shlex
1919
import sys
@@ -114,7 +114,7 @@ class ExitCode(enum.IntEnum):
114114
class ConftestImportFailure(Exception):
115115
def __init__(
116116
self,
117-
path: Path,
117+
path: pathlib.Path,
118118
*,
119119
cause: Exception,
120120
) -> None:
@@ -290,7 +290,7 @@ def get_config(
290290
invocation_params=Config.InvocationParams(
291291
args=args or (),
292292
plugins=plugins,
293-
dir=Path.cwd(),
293+
dir=pathlib.Path.cwd(),
294294
),
295295
)
296296

@@ -347,7 +347,7 @@ def _prepareconfig(
347347
raise
348348

349349

350-
def _get_directory(path: Path) -> Path:
350+
def _get_directory(path: pathlib.Path) -> pathlib.Path:
351351
"""Get the directory of a path - itself if already a directory."""
352352
if path.is_file():
353353
return path.parent
@@ -408,9 +408,9 @@ def __init__(self) -> None:
408408
# All conftest modules applicable for a directory.
409409
# This includes the directory's own conftest modules as well
410410
# as those of its parent directories.
411-
self._dirpath2confmods: dict[Path, list[types.ModuleType]] = {}
411+
self._dirpath2confmods: dict[pathlib.Path, list[types.ModuleType]] = {}
412412
# Cutoff directory above which conftests are no longer discovered.
413-
self._confcutdir: Path | None = None
413+
self._confcutdir: pathlib.Path | None = None
414414
# If set, conftest loading is skipped.
415415
self._noconftest = False
416416

@@ -544,12 +544,12 @@ def pytest_configure(self, config: Config) -> None:
544544
#
545545
def _set_initial_conftests(
546546
self,
547-
args: Sequence[str | Path],
547+
args: Sequence[str | pathlib.Path],
548548
pyargs: bool,
549549
noconftest: bool,
550-
rootpath: Path,
551-
confcutdir: Path | None,
552-
invocation_dir: Path,
550+
rootpath: pathlib.Path,
551+
confcutdir: pathlib.Path | None,
552+
invocation_dir: pathlib.Path,
553553
importmode: ImportMode | str,
554554
*,
555555
consider_namespace_packages: bool,
@@ -593,7 +593,7 @@ def _set_initial_conftests(
593593
consider_namespace_packages=consider_namespace_packages,
594594
)
595595

596-
def _is_in_confcutdir(self, path: Path) -> bool:
596+
def _is_in_confcutdir(self, path: pathlib.Path) -> bool:
597597
"""Whether to consider the given path to load conftests from."""
598598
if self._confcutdir is None:
599599
return True
@@ -610,9 +610,9 @@ def _is_in_confcutdir(self, path: Path) -> bool:
610610

611611
def _try_load_conftest(
612612
self,
613-
anchor: Path,
613+
anchor: pathlib.Path,
614614
importmode: str | ImportMode,
615-
rootpath: Path,
615+
rootpath: pathlib.Path,
616616
*,
617617
consider_namespace_packages: bool,
618618
) -> None:
@@ -635,9 +635,9 @@ def _try_load_conftest(
635635

636636
def _loadconftestmodules(
637637
self,
638-
path: Path,
638+
path: pathlib.Path,
639639
importmode: str | ImportMode,
640-
rootpath: Path,
640+
rootpath: pathlib.Path,
641641
*,
642642
consider_namespace_packages: bool,
643643
) -> None:
@@ -665,14 +665,14 @@ def _loadconftestmodules(
665665
clist.append(mod)
666666
self._dirpath2confmods[directory] = clist
667667

668-
def _getconftestmodules(self, path: Path) -> Sequence[types.ModuleType]:
668+
def _getconftestmodules(self, path: pathlib.Path) -> Sequence[types.ModuleType]:
669669
directory = self._get_directory(path)
670670
return self._dirpath2confmods.get(directory, ())
671671

672672
def _rget_with_confmod(
673673
self,
674674
name: str,
675-
path: Path,
675+
path: pathlib.Path,
676676
) -> tuple[types.ModuleType, Any]:
677677
modules = self._getconftestmodules(path)
678678
for mod in reversed(modules):
@@ -684,9 +684,9 @@ def _rget_with_confmod(
684684

685685
def _importconftest(
686686
self,
687-
conftestpath: Path,
687+
conftestpath: pathlib.Path,
688688
importmode: str | ImportMode,
689-
rootpath: Path,
689+
rootpath: pathlib.Path,
690690
*,
691691
consider_namespace_packages: bool,
692692
) -> types.ModuleType:
@@ -738,7 +738,7 @@ def _importconftest(
738738
def _check_non_top_pytest_plugins(
739739
self,
740740
mod: types.ModuleType,
741-
conftestpath: Path,
741+
conftestpath: pathlib.Path,
742742
) -> None:
743743
if (
744744
hasattr(mod, "pytest_plugins")
@@ -995,15 +995,15 @@ class InvocationParams:
995995
"""The command-line arguments as passed to :func:`pytest.main`."""
996996
plugins: Sequence[str | _PluggyPlugin] | None
997997
"""Extra plugins, might be `None`."""
998-
dir: Path
999-
"""The directory from which :func:`pytest.main` was invoked."""
998+
dir: pathlib.Path
999+
"""The directory from which :func:`pytest.main` was invoked. :type: pathlib.Path"""
10001000

10011001
def __init__(
10021002
self,
10031003
*,
10041004
args: Iterable[str],
10051005
plugins: Sequence[str | _PluggyPlugin] | None,
1006-
dir: Path,
1006+
dir: pathlib.Path,
10071007
) -> None:
10081008
object.__setattr__(self, "args", tuple(args))
10091009
object.__setattr__(self, "plugins", plugins)
@@ -1037,7 +1037,7 @@ def __init__(
10371037

10381038
if invocation_params is None:
10391039
invocation_params = self.InvocationParams(
1040-
args=(), plugins=None, dir=Path.cwd()
1040+
args=(), plugins=None, dir=pathlib.Path.cwd()
10411041
)
10421042

10431043
self.option = argparse.Namespace()
@@ -1088,7 +1088,7 @@ def __init__(
10881088
self.args: list[str] = []
10891089

10901090
@property
1091-
def rootpath(self) -> Path:
1091+
def rootpath(self) -> pathlib.Path:
10921092
"""The path to the :ref:`rootdir <rootdir>`.
10931093
10941094
:type: pathlib.Path
@@ -1098,11 +1098,9 @@ def rootpath(self) -> Path:
10981098
return self._rootpath
10991099

11001100
@property
1101-
def inipath(self) -> Path | None:
1101+
def inipath(self) -> pathlib.Path | None:
11021102
"""The path to the :ref:`configfile <configfiles>`.
11031103
1104-
:type: Optional[pathlib.Path]
1105-
11061104
.. versionadded:: 6.1
11071105
"""
11081106
return self._inipath
@@ -1313,8 +1311,8 @@ def _decide_args(
13131311
args: list[str],
13141312
pyargs: bool,
13151313
testpaths: list[str],
1316-
invocation_dir: Path,
1317-
rootpath: Path,
1314+
invocation_dir: pathlib.Path,
1315+
rootpath: pathlib.Path,
13181316
warn: bool,
13191317
) -> tuple[list[str], ArgsSource]:
13201318
"""Decide the args (initial paths/nodeids) to use given the relevant inputs.
@@ -1640,17 +1638,19 @@ def _getini(self, name: str):
16401638
else:
16411639
return self._getini_unknown_type(name, type, value)
16421640

1643-
def _getconftest_pathlist(self, name: str, path: Path) -> list[Path] | None:
1641+
def _getconftest_pathlist(
1642+
self, name: str, path: pathlib.Path
1643+
) -> list[pathlib.Path] | None:
16441644
try:
16451645
mod, relroots = self.pluginmanager._rget_with_confmod(name, path)
16461646
except KeyError:
16471647
return None
16481648
assert mod.__file__ is not None
1649-
modpath = Path(mod.__file__).parent
1650-
values: list[Path] = []
1649+
modpath = pathlib.Path(mod.__file__).parent
1650+
values: list[pathlib.Path] = []
16511651
for relroot in relroots:
16521652
if isinstance(relroot, os.PathLike):
1653-
relroot = Path(relroot)
1653+
relroot = pathlib.Path(relroot)
16541654
else:
16551655
relroot = relroot.replace("/", os.sep)
16561656
relroot = absolutepath(modpath / relroot)

src/_pytest/pytester.py

+4
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ def mkdir(self, name: str | os.PathLike[str]) -> Path:
909909
The name of the directory, relative to the pytester path.
910910
:returns:
911911
The created directory.
912+
:rtype: pathlib.Path
912913
"""
913914
p = self.path / name
914915
p.mkdir()
@@ -932,6 +933,7 @@ def copy_example(self, name: str | None = None) -> Path:
932933
The name of the file to copy.
933934
:return:
934935
Path to the copied directory (inside ``self.path``).
936+
:rtype: pathlib.Path
935937
"""
936938
example_dir_ = self._request.config.getini("pytester_example_dir")
937939
if example_dir_ is None:
@@ -1390,8 +1392,10 @@ def run(
13901392
- Otherwise, it is passed through to :py:class:`subprocess.Popen`.
13911393
For further information in this case, consult the document of the
13921394
``stdin`` parameter in :py:class:`subprocess.Popen`.
1395+
:type stdin: _pytest.compat.NotSetType | bytes | IO[Any] | int
13931396
:returns:
13941397
The result.
1398+
13951399
"""
13961400
__tracebackhide__ = True
13971401

src/_pytest/python.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ def parametrize(
11681168
If N argnames were specified, argvalues must be a list of
11691169
N-tuples, where each tuple-element specifies a value for its
11701170
respective argname.
1171-
1171+
:type argvalues: Iterable[_pytest.mark.structures.ParameterSet | Sequence[object] | object]
11721172
:param indirect:
11731173
A list of arguments' names (subset of argnames) or a boolean.
11741174
If True the list contains all names from the argnames. Each

src/_pytest/runner.py

+1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def from_call(
327327
328328
:param func:
329329
The function to call. Called without arguments.
330+
:type func: Callable[[], _pytest.runner.TResult]
330331
:param when:
331332
The phase in which the function is called.
332333
:param reraise:

tox.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ setenv =
8181
PYTHONWARNDEFAULTENCODING=
8282

8383
[testenv:docs]
84-
basepython = python3
84+
basepython = python3.9 # sync with rtd to get errors
8585
usedevelop = True
8686
deps =
8787
-r{toxinidir}/doc/en/requirements.txt
8888
# https://github.com/twisted/towncrier/issues/340
8989
towncrier<21.3.0
90+
91+
92+
9093
commands =
9194
python scripts/towncrier-draft-to-file.py
9295
# the '-t changelog_towncrier_draft' tags makes sphinx include the draft

0 commit comments

Comments
 (0)