From 0ffd0497e87b2613bddbe8c27d0b1885184a0692 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Tue, 8 Sep 2026 07:06:24 +0100 Subject: [PATCH 1/2] monkeypatch: annotate the path parameter of syspath_prepend The parameter had no annotation, so a strict type checker such as pyright reports every call as having a partially unknown type. The method accepts anything str() can turn into a path, and it is documented alongside chdir, which already takes str | os.PathLike[str]. Co-Authored-By: Claude Fable 5.1 --- AUTHORS | 1 + src/_pytest/monkeypatch.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index daa6a471eb9..ae04e587921 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Abdeali JK Abdelrahman Elbehery Abhijeet Kasurde ace2016 +Adam Dangoor Adam Johnson Adam Stewart Adam Uhlir diff --git a/src/_pytest/monkeypatch.py b/src/_pytest/monkeypatch.py index 453c6728ee2..d4f5695be9e 100644 --- a/src/_pytest/monkeypatch.py +++ b/src/_pytest/monkeypatch.py @@ -360,7 +360,7 @@ def delenv(self, name: str, raising: bool = True) -> None: environ: MutableMapping[str, str] = os.environ self.delitem(environ, name, raising=raising) - def syspath_prepend(self, path) -> None: + def syspath_prepend(self, path: str | os.PathLike[str]) -> None: """Prepend ``path`` to ``sys.path`` list of import locations.""" if self._savesyspath is None: self._savesyspath = sys.path[:] From 1a42cd4910e522e443c2c6b01c78d235af26282a Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Tue, 8 Sep 2026 07:06:37 +0100 Subject: [PATCH 2/2] Add changelog entry for #14988 --- changelog/14988.improvement.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/14988.improvement.rst diff --git a/changelog/14988.improvement.rst b/changelog/14988.improvement.rst new file mode 100644 index 00000000000..724425456e0 --- /dev/null +++ b/changelog/14988.improvement.rst @@ -0,0 +1 @@ +:meth:`MonkeyPatch.syspath_prepend ` now annotates its ``path`` parameter as ``str | os.PathLike[str]``, so strict type checkers no longer report calls to it as having an unknown type.