Coverage for C:\Users\t590r\Documents\GitHub\suppy\suppy\utils\_func_wrapper.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2025-02-05 10:12 +0100

1from typing import Callable 

2 

3 

4class FuncWrapper: 

5 """ 

6 A callable class for a function that keeps track of the number of times 

7 it is called. 

8 

9 Parameters 

10 ---------- 

11 func : Callable 

12 The function to be wrapped. 

13 args : list 

14 The arguments to be passed to the function. 

15 

16 Attributes 

17 ---------- 

18 func : Callable 

19 The function to be wrapped. 

20 args : list 

21 The arguments to be passed to the function. 

22 fcount : int 

23 The number of times the function has been called. 

24 """ 

25 

26 def __init__(self, func: Callable, args=[]): 

27 self.func = func 

28 self.args = args 

29 self.fcount = 0 

30 

31 def __call__(self, x): 

32 self.fcount += 1 

33 return self.func(x, *self.args)