From 895164c56dcbe0126fa6c413f70c803e9ed81449 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Wed, 13 Jul 2022 18:13:22 -0700 Subject: [PATCH 1/3] Add typing for FixtureRequest.param For now, mark it as Any until #8073 is solved Fixes #9514 --- AUTHORS | 1 + changelog/9514.bugfix.rst | 1 + src/_pytest/fixtures.py | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog/9514.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 09fe12e004f..b0669ba29fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -252,6 +252,7 @@ Nicholas Murphy Niclas Olofsson Nicolas Delaby Nikolay Kondratyev +Nipunn Koorapati Olga Matoula Oleg Pidsadnyi Oleg Sushchenko diff --git a/changelog/9514.bugfix.rst b/changelog/9514.bugfix.rst new file mode 100644 index 00000000000..d4b2280effb --- /dev/null +++ b/changelog/9514.bugfix.rst @@ -0,0 +1 @@ +Type FixtureRequest.param as Any. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 32c3ec4b0bf..4975be8203d 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -345,7 +345,7 @@ def reorder_items_atscope( return items_done -def get_direct_param_fixture_func(request): +def get_direct_param_fixture_func(request: "FixtureRequest") -> Any: return request.param @@ -407,6 +407,7 @@ def __init__(self, pyfuncitem, *, _ispytest: bool = False) -> None: self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy() self._arg2index: Dict[str, int] = {} self._fixturemanager: FixtureManager = pyfuncitem.session._fixturemanager + self.param: Any @property def scope(self) -> "_ScopeName": From c40411749a6299236e07581b9d72457ad7de4fb7 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Thu, 14 Jul 2022 10:52:03 -0700 Subject: [PATCH 2/3] Update changelog/9514.bugfix.rst Co-authored-by: Bruno Oliveira --- changelog/9514.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/9514.bugfix.rst b/changelog/9514.bugfix.rst index d4b2280effb..a940b5c72d5 100644 --- a/changelog/9514.bugfix.rst +++ b/changelog/9514.bugfix.rst @@ -1 +1 @@ -Type FixtureRequest.param as Any. +Type-annotate ``FixtureRequest.param`` as ``Any`` as a stop gap measure until :issue:`8073` is fixed. From 208638323c3c6326c85f704e0133d93859c8984e Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Thu, 14 Jul 2022 13:24:16 -0700 Subject: [PATCH 3/3] Update src/_pytest/fixtures.py Co-authored-by: Ran Benita --- src/_pytest/fixtures.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 4975be8203d..d1d36d7fa24 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -407,6 +407,14 @@ def __init__(self, pyfuncitem, *, _ispytest: bool = False) -> None: self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy() self._arg2index: Dict[str, int] = {} self._fixturemanager: FixtureManager = pyfuncitem.session._fixturemanager + # Notes on the type of `param`: + # -`request.param` is only defined in parametrized fixtures, and will raise + # AttributeError otherwise. Python typing has no notion of "undefined", so + # this cannot be reflected in the type. + # - Technically `param` is only (possibly) defined on SubRequest, not + # FixtureRequest, but the typing of that is still in flux so this cheats. + # - In the future we might consider using a generic for the param type, but + # for now just using Any. self.param: Any @property