11from collections .abc import Callable
22from enum import Enum
33from functools import wraps
4- from typing import TypeVar , cast
4+ from typing import ParamSpec , TypeVar
55
66from bluesky import preprocessors as bpp
77from bluesky .callbacks .fitting import PeakStats
@@ -38,10 +38,14 @@ class StatPosition(tuple, Enum):
3838 D_MAX = ("derivative_stats" , "max" )
3939
4040
41- TCallable = TypeVar ("TCallable" , bound = Callable )
41+ P = ParamSpec ("P" )
42+ T = TypeVar ("T" )
43+ TCallable = Callable [
44+ P , T
45+ ] # Type for callable functions with parameters P and return type T
4246
4347
44- def scan_and_move_to_fit_pos (funcs : TCallable ) -> TCallable :
48+ def scan_and_move_to_fit_pos (func : TCallable ) -> TCallable :
4549 """
4650 Wrapper to add a PeakStats callback before performing a scan
4751 and move to the fitted position after the scan.
@@ -57,30 +61,30 @@ def scan_and_move_to_fit_pos(funcs: TCallable) -> TCallable:
5761 The wrapped scan function.
5862 """
5963
60- @wraps (funcs )
64+ @wraps (func )
6165 def inner (
6266 det : StandardReadable ,
6367 motor : Motor ,
6468 fitted_loc : StatPosition ,
6569 detname_suffix : str ,
6670 * args ,
6771 ** kwargs ,
68- ):
72+ ) -> MsgGenerator :
6973 ps = PeakStats (
7074 f"{ motor .name } " ,
7175 f"{ det .name } -{ detname_suffix } " ,
7276 calc_derivative_and_stats = True ,
7377 )
7478 yield from bpp .subs_wrapper (
75- funcs (det , motor , fitted_loc , detname_suffix , * args , ** kwargs ),
79+ func (det , motor , fitted_loc , detname_suffix , * args , ** kwargs ),
7680 ps ,
7781 )
7882 peak_position = get_stat_loc (ps , fitted_loc )
7983
8084 LOGGER .info (f"Fit info { ps } " )
8185 yield from abs_set (motor , peak_position , wait = True )
8286
83- return cast ( TCallable , inner )
87+ return inner
8488
8589
8690@plan
0 commit comments