Coverage for src/configuraptor/postpone.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-20 10:44 +0200

1""" 

2File contains logic to do with the 'postpone' feature. 

3""" 

4 

5from typing import Any 

6 

7from typing_extensions import Never 

8 

9from .errors import IsPostponedError 

10from .singleton import Singleton 

11 

12 

13class Postponed(Singleton): 

14 """ 

15 Class returned by `postpone` below. 

16 """ 

17 

18 def __get__(self, instance: type[Any], owner: type[Any]) -> Never: 

19 """ 

20 This magic method is called when a property is accessed. 

21 

22 Example: 

23 someclass.someprop will trigger the __get__ of `someprop` 

24 

25 Args: 

26 instance: the class on which the postponed property is defined, 

27 owner: `SingletonMeta` 

28 """ 

29 raise IsPostponedError() 

30 

31 

32def postpone() -> Any: 

33 """ 

34 Can be used to mark a property as postponed, meaning the user will fill it in later (they promose). 

35 

36 If they don't fill it in and still try to use it, they will be met with a IsPostponedError. 

37 """ 

38 return Postponed()