Coverage for packages/core/src/integrify/utils.py: 90%

28 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-10-19 02:39 +0000

1from enum import Enum 

2from typing import Annotated, Literal, TypeVar 

3 

4from pydantic import BaseModel, Field 

5 

6_ResponseT = TypeVar('_ResponseT', bound=BaseModel | dict | list) 

7"""Dynamic response type. 

8 

9Bəzi API-lər (məs., E-Customs) kök səviyyəsində JSON array qaytarır, ona görə 

10`list` də bound-a daxildir (`APIResponse[list[SomeSchema]]`). 

11""" 

12 

13T = TypeVar('T') 

14 

15 

16class UnsetType: 

17 """Sentinel type to indicate an unset field value.""" 

18 

19 _instance = None 

20 

21 def __new__(cls): 

22 if cls._instance is None: 22 ↛ 24line 22 didn't jump to line 24 because the condition on line 22 was always true

23 cls._instance = super().__new__(cls) 

24 return cls._instance 

25 

26 def __repr__(self): 

27 return '<UNSET>' 

28 

29 def __str__(self): 

30 return 'UNSET' 

31 

32 def __bool__(self): 

33 return False 

34 

35 

36UNSET = UnsetType() 

37 

38Unset = T | Literal[UNSET] 

39""" Optional argument tipi """ 

40 

41UnsetOrNone = T | Literal[UNSET] | None 

42"""None dəyəri ala bilən optional argument tipi""" 

43 

44UnsetField = Annotated[Unset[T], Field(default=UNSET, exclude_if=lambda x: x is UNSET)] 

45"""Pydantic üçün set olunmamış argument dəyəri""" 

46 

47UnsetOrNoneField = Annotated[UnsetOrNone[T], Field(default=UNSET, exclude_if=lambda x: x is UNSET)] 

48"""Pydantic üçün set olunmamış və None dəyəri ala bilən argument dəyəri""" 

49 

50 

51class Environment(str, Enum): 

52 TEST = 'test' 

53 PROD = 'prod'