Skip to content

Commit 44ad01d

Browse files
resolve most sphinx lookup errors
add the extra sphinx annotations to refer to Path instances add Path to nitpicky ignore
1 parent 1d14003 commit 44ad01d

File tree

9 files changed

+65
-39
lines changed

9 files changed

+65
-39
lines changed

doc/en/conf.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
from textwrap import dedent
2222
from typing import TYPE_CHECKING
2323

24-
from _pytest import __version__ as version
24+
from _pytest import __version__ as full_version
2525

2626

27+
version = full_version.split("+")[0]
28+
2729
if TYPE_CHECKING:
2830
import sphinx.application
2931

@@ -178,6 +180,7 @@
178180
("py:class", "SubRequest"),
179181
("py:class", "TerminalReporter"),
180182
("py:class", "_pytest._code.code.TerminalRepr"),
183+
("py:class", "TerminalRepr"),
181184
("py:class", "_pytest.fixtures.FixtureFunctionMarker"),
182185
("py:class", "_pytest.logging.LogCaptureHandler"),
183186
("py:class", "_pytest.mark.structures.ParameterSet"),
@@ -199,13 +202,16 @@
199202
("py:class", "_PluggyPlugin"),
200203
# TypeVars
201204
("py:class", "_pytest._code.code.E"),
205+
("py:class", "E"), # due to delayed annotation
202206
("py:class", "_pytest.fixtures.FixtureFunction"),
203207
("py:class", "_pytest.nodes._NodeType"),
208+
("py:class", "_NodeType"), # due to delayed annotation
204209
("py:class", "_pytest.python_api.E"),
205210
("py:class", "_pytest.recwarn.T"),
206211
("py:class", "_pytest.runner.TResult"),
207212
("py:obj", "_pytest.fixtures.FixtureValue"),
208213
("py:obj", "_pytest.stash.T"),
214+
("py:class", "_ScopeName"),
209215
]
210216

211217

src/_pytest/_code/code.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ def getrepr(
620620
showlocals: bool = False,
621621
style: TracebackStyle = "long",
622622
abspath: bool = False,
623-
tbfilter: bool | Callable[[ExceptionInfo[BaseException]], Traceback] = True,
623+
tbfilter: bool
624+
| Callable[[ExceptionInfo[BaseException]], _pytest._code.code.Traceback] = True,
624625
funcargs: bool = False,
625626
truncate_locals: bool = True,
626627
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/hookspec.py

+6
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def pytest_ignore_collect(
321321
Stops at first non-None result, see :ref:`firstresult`.
322322
323323
:param collection_path: The path to analyze.
324+
:type collection_path: pathlib.Path
324325
:param path: The path to analyze (deprecated).
325326
:param config: The pytest config object.
326327
@@ -354,6 +355,7 @@ def pytest_collect_directory(path: Path, parent: Collector) -> Collector | None:
354355
Stops at first non-None result, see :ref:`firstresult`.
355356
356357
:param path: The path to analyze.
358+
:type path: pathlib.Path
357359
358360
See :ref:`custom directory collectors` for a simple example of use of this
359361
hook.
@@ -386,6 +388,7 @@ def pytest_collect_file(
386388
The new node needs to have the specified ``parent`` as a parent.
387389
388390
:param file_path: The path to analyze.
391+
:type file_path: pathlib.Path
389392
:param path: The path to collect (deprecated).
390393
391394
.. versionchanged:: 7.0.0
@@ -507,6 +510,7 @@ def pytest_pycollect_makemodule(
507510
Stops at first non-None result, see :ref:`firstresult`.
508511
509512
:param module_path: The path of the module to collect.
513+
:type module_path: pathlib.Path
510514
:param path: The path of the module to collect (deprecated).
511515
512516
.. versionchanged:: 7.0.0
@@ -1026,6 +1030,7 @@ def pytest_report_header( # type:ignore[empty-body]
10261030
10271031
:param config: The pytest config object.
10281032
:param start_path: The starting dir.
1033+
:type start_path: pathlib.Path
10291034
:param startdir: The starting dir (deprecated).
10301035
10311036
.. note::
@@ -1069,6 +1074,7 @@ def pytest_report_collectionfinish( # type:ignore[empty-body]
10691074
10701075
:param config: The pytest config object.
10711076
:param start_path: The starting dir.
1077+
:type start_path: pathlib.Path
10721078
:param startdir: The starting dir (deprecated).
10731079
:param items: List of pytest items that are going to be executed; this list should not be modified.
10741080

src/_pytest/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def from_parent( # type: ignore[override]
510510
511511
:param parent: The parent collector of this Dir.
512512
:param path: The directory's path.
513+
:type path: pathlib.Path
513514
"""
514515
return super().from_parent(parent=parent, path=path)
515516

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,25 @@ 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
9396
# changelog in the docs; this does not happen on ReadTheDocs because it uses
9497
# the standard sphinx command so the 'changelog_towncrier_draft' is never set there
95-
sphinx-build -W --keep-going -b html doc/en doc/en/_build/html -t changelog_towncrier_draft {posargs:}
98+
sphinx-build \
99+
-j auto \
100+
-W --keep-going \
101+
-b html doc/en doc/en/_build/html \
102+
-t changelog_towncrier_draft {posargs:}
96103
setenv =
97104
# Sphinx is not clean of this warning.
98105
PYTHONWARNDEFAULTENCODING=

0 commit comments

Comments
 (0)