Skip to content

Commit

Permalink
resolve most sphinx lookup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Jun 18, 2024
1 parent a71f079 commit 798c82c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
8 changes: 8 additions & 0 deletions doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
autodoc_member_order = "bysource"
autodoc_typehints = "description"
autodoc_typehints_description_target = "documented"



autodoc2_packages = ["pytest", "_pytest"]
todo_include_todos = 1

latex_engine = "lualatex"
Expand Down Expand Up @@ -180,6 +184,7 @@
("py:class", "SubRequest"),
("py:class", "TerminalReporter"),
("py:class", "_pytest._code.code.TerminalRepr"),
("py:class", "TerminalRepr"),
("py:class", "_pytest.fixtures.FixtureFunctionMarker"),
("py:class", "_pytest.logging.LogCaptureHandler"),
("py:class", "_pytest.mark.structures.ParameterSet"),
Expand All @@ -201,13 +206,16 @@
("py:class", "_PluggyPlugin"),
# TypeVars
("py:class", "_pytest._code.code.E"),
("py:class", "E"), # due to delayed annotation
("py:class", "_pytest.fixtures.FixtureFunction"),
("py:class", "_pytest.nodes._NodeType"),
("py:class", "_NodeType"), # due to delayed annotation
("py:class", "_pytest.python_api.E"),
("py:class", "_pytest.recwarn.T"),
("py:class", "_pytest.runner.TResult"),
("py:obj", "_pytest.fixtures.FixtureValue"),
("py:obj", "_pytest.stash.T"),
("py:class", "_ScopeName"),
]


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ def getrepr(
showlocals: bool = False,
style: TracebackStyle = "long",
abspath: bool = False,
tbfilter: bool | Callable[[ExceptionInfo[BaseException]], Traceback] = True,
tbfilter: bool
| Callable[[ExceptionInfo[BaseException]], _pytest._code.code.Traceback] = True,
funcargs: bool = False,
truncate_locals: bool = True,
truncate_args: bool = True,
Expand Down
68 changes: 34 additions & 34 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import importlib.metadata
import inspect
import os
from pathlib import Path
import pathlib
import re
import shlex
import sys
Expand Down Expand Up @@ -114,7 +114,7 @@ class ExitCode(enum.IntEnum):
class ConftestImportFailure(Exception):
def __init__(
self,
path: Path,
path: pathlib.Path,
*,
cause: Exception,
) -> None:
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_config(
invocation_params=Config.InvocationParams(
args=args or (),
plugins=plugins,
dir=Path.cwd(),
dir=pathlib.Path.cwd(),
),
)

Expand Down Expand Up @@ -347,7 +347,7 @@ def _prepareconfig(
raise


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

Expand Down Expand Up @@ -544,12 +544,12 @@ def pytest_configure(self, config: Config) -> None:
#
def _set_initial_conftests(
self,
args: Sequence[str | Path],
args: Sequence[str | pathlib.Path],
pyargs: bool,
noconftest: bool,
rootpath: Path,
confcutdir: Path | None,
invocation_dir: Path,
rootpath: pathlib.Path,
confcutdir: pathlib.Path | None,
invocation_dir: pathlib.Path,
importmode: ImportMode | str,
*,
consider_namespace_packages: bool,
Expand Down Expand Up @@ -593,7 +593,7 @@ def _set_initial_conftests(
consider_namespace_packages=consider_namespace_packages,
)

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

def _try_load_conftest(
self,
anchor: Path,
anchor: pathlib.Path,
importmode: str | ImportMode,
rootpath: Path,
rootpath: pathlib.Path,
*,
consider_namespace_packages: bool,
) -> None:
Expand All @@ -635,9 +635,9 @@ def _try_load_conftest(

def _loadconftestmodules(
self,
path: Path,
path: pathlib.Path,
importmode: str | ImportMode,
rootpath: Path,
rootpath: pathlib.Path,
*,
consider_namespace_packages: bool,
) -> None:
Expand Down Expand Up @@ -665,14 +665,14 @@ def _loadconftestmodules(
clist.append(mod)
self._dirpath2confmods[directory] = clist

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

def _rget_with_confmod(
self,
name: str,
path: Path,
path: pathlib.Path,
) -> tuple[types.ModuleType, Any]:
modules = self._getconftestmodules(path)
for mod in reversed(modules):
Expand All @@ -684,9 +684,9 @@ def _rget_with_confmod(

def _importconftest(
self,
conftestpath: Path,
conftestpath: pathlib.Path,
importmode: str | ImportMode,
rootpath: Path,
rootpath: pathlib.Path,
*,
consider_namespace_packages: bool,
) -> types.ModuleType:
Expand Down Expand Up @@ -738,7 +738,7 @@ def _importconftest(
def _check_non_top_pytest_plugins(
self,
mod: types.ModuleType,
conftestpath: Path,
conftestpath: pathlib.Path,
) -> None:
if (
hasattr(mod, "pytest_plugins")
Expand Down Expand Up @@ -995,15 +995,15 @@ class InvocationParams:
"""The command-line arguments as passed to :func:`pytest.main`."""
plugins: Sequence[str | _PluggyPlugin] | None
"""Extra plugins, might be `None`."""
dir: Path
"""The directory from which :func:`pytest.main` was invoked."""
dir: pathlib.Path
"""The directory from which :func:`pytest.main` was invoked. :type: pathlib.Path"""

def __init__(
self,
*,
args: Iterable[str],
plugins: Sequence[str | _PluggyPlugin] | None,
dir: Path,
dir: pathlib.Path,
) -> None:
object.__setattr__(self, "args", tuple(args))
object.__setattr__(self, "plugins", plugins)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def __init__(

if invocation_params is None:
invocation_params = self.InvocationParams(
args=(), plugins=None, dir=Path.cwd()
args=(), plugins=None, dir=pathlib.Path.cwd()
)

self.option = argparse.Namespace()
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def __init__(
self.args: list[str] = []

@property
def rootpath(self) -> Path:
def rootpath(self) -> pathlib.Path:
"""The path to the :ref:`rootdir <rootdir>`.
:type: pathlib.Path
Expand All @@ -1098,11 +1098,9 @@ def rootpath(self) -> Path:
return self._rootpath

@property
def inipath(self) -> Path | None:
def inipath(self) -> pathlib.Path | None:
"""The path to the :ref:`configfile <configfiles>`.
:type: Optional[pathlib.Path]
.. versionadded:: 6.1
"""
return self._inipath
Expand Down Expand Up @@ -1313,8 +1311,8 @@ def _decide_args(
args: list[str],
pyargs: bool,
testpaths: list[str],
invocation_dir: Path,
rootpath: Path,
invocation_dir: pathlib.Path,
rootpath: pathlib.Path,
warn: bool,
) -> tuple[list[str], ArgsSource]:
"""Decide the args (initial paths/nodeids) to use given the relevant inputs.
Expand Down Expand Up @@ -1640,17 +1638,19 @@ def _getini(self, name: str):
else:
return self._getini_unknown_type(name, type, value)

def _getconftest_pathlist(self, name: str, path: Path) -> list[Path] | None:
def _getconftest_pathlist(
self, name: str, path: pathlib.Path
) -> list[pathlib.Path] | None:
try:
mod, relroots = self.pluginmanager._rget_with_confmod(name, path)
except KeyError:
return None
assert mod.__file__ is not None
modpath = Path(mod.__file__).parent
values: list[Path] = []
modpath = pathlib.Path(mod.__file__).parent
values: list[pathlib.Path] = []
for relroot in relroots:
if isinstance(relroot, os.PathLike):
relroot = Path(relroot)
relroot = pathlib.Path(relroot)
else:
relroot = relroot.replace("/", os.sep)
relroot = absolutepath(modpath / relroot)
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ def mkdir(self, name: str | os.PathLike[str]) -> Path:
The name of the directory, relative to the pytester path.
:returns:
The created directory.
:rtype: pathlib.Path
"""
p = self.path / name
p.mkdir()
Expand All @@ -932,6 +933,7 @@ def copy_example(self, name: str | None = None) -> Path:
The name of the file to copy.
:return:
Path to the copied directory (inside ``self.path``).
:rtype: pathlib.Path
"""
example_dir_ = self._request.config.getini("pytester_example_dir")
if example_dir_ is None:
Expand Down Expand Up @@ -1390,8 +1392,10 @@ def run(
- Otherwise, it is passed through to :py:class:`subprocess.Popen`.
For further information in this case, consult the document of the
``stdin`` parameter in :py:class:`subprocess.Popen`.
:type stdin: _pytest.compat.NotSetType | bytes | IO[Any] | int
:returns:
The result.
"""
__tracebackhide__ = True

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ def parametrize(
If N argnames were specified, argvalues must be a list of
N-tuples, where each tuple-element specifies a value for its
respective argname.
:type argvalues: Iterable[_pytest.mark.structures.ParameterSet | Sequence[object] | object]
:param indirect:
A list of arguments' names (subset of argnames) or a boolean.
If True the list contains all names from the argnames. Each
Expand Down
1 change: 1 addition & 0 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def from_call(
:param func:
The function to call. Called without arguments.
:type func: Callable[[], _pytest.runner.TResult]
:param when:
The phase in which the function is called.
:param reraise:
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ setenv =
PYTHONWARNDEFAULTENCODING=

[testenv:docs]
basepython = python3
basepython = python3.9 # sync with rtd to get errors
usedevelop = True
deps =
-r{toxinidir}/doc/en/requirements.txt
# https://github.com/twisted/towncrier/issues/340
towncrier<21.3.0



commands =
python scripts/towncrier-draft-to-file.py
# the '-t changelog_towncrier_draft' tags makes sphinx include the draft
Expand Down

0 comments on commit 798c82c

Please sign in to comment.