From 034f17cf084b397a56969c59eec2ff33e6bb7288 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sat, 11 Jun 2022 14:07:33 +0200 Subject: [PATCH] TypeVar for Box has to be covariant --- pytest_factoryboy/fixture.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pytest_factoryboy/fixture.py b/pytest_factoryboy/fixture.py index f77f2f8..db1182a 100644 --- a/pytest_factoryboy/fixture.py +++ b/pytest_factoryboy/fixture.py @@ -41,6 +41,7 @@ FactoryType: TypeAlias = Type[factory.Factory] F = TypeVar("F", bound=FactoryType) T = TypeVar("T") +T_co = TypeVar("T_co", covariant=True) P = ParamSpec("P") SEPARATOR = "__" @@ -58,16 +59,16 @@ def __call__(self, request: SubRequest) -> Any: return self.function(request) -class Box(Generic[T]): +class Box(Generic[T_co]): """Simple box class, used to hold a value. The main purpose of this is to hold objects that we don't want to appear in stack traces. For example, the "caller_locals" dict holding a lot of items. """ - value: T + value: T_co - def __init__(self, value: T): + def __init__(self, value: T_co): self.value = value