Skip to content

Commit c1d1341

Browse files
authored
Add typing for FixtureRequest.param (#10133)
For now, mark it as Any until #8073 is solved Fixes #9514
1 parent cbcb3a3 commit c1d1341

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ Nicholas Murphy
252252
Niclas Olofsson
253253
Nicolas Delaby
254254
Nikolay Kondratyev
255+
Nipunn Koorapati
255256
Olga Matoula
256257
Oleg Pidsadnyi
257258
Oleg Sushchenko

changelog/9514.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Type-annotate ``FixtureRequest.param`` as ``Any`` as a stop gap measure until :issue:`8073` is fixed.

src/_pytest/fixtures.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def reorder_items_atscope(
345345
return items_done
346346

347347

348-
def get_direct_param_fixture_func(request):
348+
def get_direct_param_fixture_func(request: "FixtureRequest") -> Any:
349349
return request.param
350350

351351

@@ -407,6 +407,15 @@ def __init__(self, pyfuncitem, *, _ispytest: bool = False) -> None:
407407
self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy()
408408
self._arg2index: Dict[str, int] = {}
409409
self._fixturemanager: FixtureManager = pyfuncitem.session._fixturemanager
410+
# Notes on the type of `param`:
411+
# -`request.param` is only defined in parametrized fixtures, and will raise
412+
# AttributeError otherwise. Python typing has no notion of "undefined", so
413+
# this cannot be reflected in the type.
414+
# - Technically `param` is only (possibly) defined on SubRequest, not
415+
# FixtureRequest, but the typing of that is still in flux so this cheats.
416+
# - In the future we might consider using a generic for the param type, but
417+
# for now just using Any.
418+
self.param: Any
410419

411420
@property
412421
def scope(self) -> "_ScopeName":

0 commit comments

Comments
 (0)