1313from datetime import datetime , timedelta , timezone
1414from decimal import Decimal
1515from functools import wraps
16- from typing import Any , Callable , Self , Type , TypeVar
16+ from typing import Callable , Concatenate , ParamSpec , Self , TypeVar
1717
1818# pylint: disable=no-member
1919from frequenz .api .common .v1 .grid import delivery_area_pb2 , delivery_duration_pb2
2626
2727
2828T = TypeVar ("T" ) # Generic type variable for class methods
29+ P = ParamSpec ("P" )
2930
3031
31- def from_pb (func : Callable [[Type [T ], Any ], T ]) -> Callable [[Type [T ], Any ], T ]:
32+ def from_pb (
33+ func : Callable [Concatenate [type [T ], P ], T ]
34+ ) -> Callable [Concatenate [type [T ], P ], T ]:
3235 """Standardize from_pb methods like error handling with this decorator.
3336
3437 Args:
@@ -39,12 +42,12 @@ def from_pb(func: Callable[[Type[T], Any], T]) -> Callable[[Type[T], Any], T]:
3942 """
4043
4144 @wraps (func )
42- def wrapper (cls : Type [T ], pb_obj : Any ) -> T :
45+ def wrapper (cls : type [T ], / , * args : P . args , ** kwargs : P . kwargs ) -> T :
4346 try :
44- return func (cls , pb_obj )
47+ return func (cls , * args , ** kwargs )
4548 except Exception as e :
4649 _logger .error (
47- "Error converting %s from protobuf (`%s`): %s" , cls .__name__ , pb_obj , e
50+ "Error converting %s from protobuf (`%s`): %s" , cls .__name__ , * args , e
4851 )
4952 raise
5053
0 commit comments