Coverage for install/scipp/core/_cpp_wrapper_util.py: 53%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-17 01:51 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Simon Heybrock 

4import itertools 

5from collections.abc import Callable 

6from typing import Any, ParamSpec, TypeVar 

7 

8from .data_group import DataGroup, data_group_nary 

9 

10_R = TypeVar('_R') 

11_P = ParamSpec('_P') 

12 

13 

14def call_func( 

15 func: Callable[_P, _R], 

16 *args: _P.args, 

17 **kwargs: _P.kwargs, 

18) -> _R | DataGroup[Any]: 

19 out = kwargs.pop('out', None) 

20 if any(isinstance(x, DataGroup) for x in itertools.chain(args, kwargs.values())): 

21 if out is not None: 

22 raise ValueError( 

23 "`out` argument is not supported for DataGroup operations." 

24 ) 

25 return data_group_nary(func, *args, **kwargs) 

26 if out is None: 

27 return func(*args, **kwargs) 

28 else: 

29 return func(*args, **kwargs, out=out) # type: ignore[arg-type]