Add typing for FixtureRequest.param (#10133)

For now, mark it as Any until #8073 is solved

Fixes #9514
This commit is contained in:
Nipunn Koorapati 2022-07-14 16:36:05 -07:00 committed by GitHub
parent cbcb3a356e
commit c1d134172c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -252,6 +252,7 @@ Nicholas Murphy
Niclas Olofsson Niclas Olofsson
Nicolas Delaby Nicolas Delaby
Nikolay Kondratyev Nikolay Kondratyev
Nipunn Koorapati
Olga Matoula Olga Matoula
Oleg Pidsadnyi Oleg Pidsadnyi
Oleg Sushchenko Oleg Sushchenko

View File

@ -0,0 +1 @@
Type-annotate ``FixtureRequest.param`` as ``Any`` as a stop gap measure until :issue:`8073` is fixed.

View File

@ -345,7 +345,7 @@ def reorder_items_atscope(
return items_done return items_done
def get_direct_param_fixture_func(request): def get_direct_param_fixture_func(request: "FixtureRequest") -> Any:
return request.param return request.param
@ -407,6 +407,15 @@ class FixtureRequest:
self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy() self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy()
self._arg2index: Dict[str, int] = {} self._arg2index: Dict[str, int] = {}
self._fixturemanager: FixtureManager = pyfuncitem.session._fixturemanager 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 @property
def scope(self) -> "_ScopeName": def scope(self) -> "_ScopeName":