99import  traceback 
1010from  enum  import  Enum 
1111from  pydantic  import  TypeAdapter , ValidationError 
12- from  typing  import  Any , Dict , Literal , Optional , Type , TypeVar , overload , TYPE_CHECKING , Union 
12+ from  typing  import  Any , Callable ,  Dict , Literal , Optional , Type , TypeVar ,  cast , overload , TYPE_CHECKING , Union 
1313from  uuid  import  UUID 
1414
1515import  pytest 
@@ -69,7 +69,6 @@ def expand_scope_relative_nodeid(scoped_nodeid, scope, ref_nodeid):
6969    logging .debug ("scope: %r base: %r relative: %r" , scope , base , scoped_nodeid )
7070    return  "::" .join (itertools .chain (base , (scoped_nodeid ,)))
7171
72- def  callable_marker (value , request ):
7372T  =  TypeVar ("T" )
7473
7574_ensure_type_cache : Dict [type , TypeAdapter ] =  {}
@@ -97,6 +96,7 @@ def ensure_type(typ: Type[T], value: Any) -> T:
9796        raise  TypeError (f"'{ type (value ).__name__ } { typ .__name__ }  )
9897    return  value 
9998
99+ def  callable_marker (value : Union [T , Callable [[], T ]], request : pytest .FixtureRequest ) ->  T :
100100    """ 
101101    Process value optionally generated by fixture-dependent callable. 
102102
@@ -112,8 +112,11 @@ def ensure_type(typ: Type[T], value: Any) -> T:
112112                      for  arg_name  in  inspect .getfullargspec (value ).args }
113113        except  pytest .FixtureLookupError  as  e :
114114            raise  RuntimeError ("fixture in mapping not found on test" ) from  e 
115-         value  =  value (** params )
116-     return  value 
115+         # callable ensures the value is of type Callable[..., object], which is not enough in that case 
116+         # we can trust the static checker though, and thus use cast 
117+         return  cast (Callable [[], T ], value )(** params )
118+     else :
119+         return  value 
117120
118121def  wait_for (fn , msg = None , timeout_secs = 2  *  60 , retry_delay_secs = 2 , invert = False ):
119122    if  msg  is  not None :
0 commit comments