Coverage for src/shephex/decorators/__init__.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-03-29 18:45 +0100

1# ruff: noqa 

2class DecoratorState: 

3 

4 def __init__(self): 

5 self._active = True 

6 

7 def disable(self): 

8 self._active = False 

9 

10 def enable(self): 

11 self._active = True 

12 

13 @property 

14 def active(self): 

15 return self._active 

16 

17global decorator_state 

18decorator_state = None 

19 

20def get_decorator_state(): 

21 global decorator_state 

22 if decorator_state is None: 

23 decorator_state = DecoratorState() 

24 return decorator_state 

25 

26from contextlib import AbstractContextManager 

27 

28class disable_decorators(AbstractContextManager): 

29 

30 def __enter__(self): 

31 get_decorator_state().disable() 

32 

33 def __exit__(self, *exc): 

34 get_decorator_state().enable() 

35 

36 

37from shephex.decorators.chain import chain 

38from shephex.decorators.hexperiment import hexperiment 

39 

40__all__ = ['chain', 'hexperiment']