Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/astroid/typing.py: 83%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 

2# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE 

3# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt 

4 

5from __future__ import annotations 

6 

7from collections.abc import Callable, Generator 

8from typing import ( 

9 TYPE_CHECKING, 

10 Any, 

11 Generic, 

12 Protocol, 

13 TypedDict, 

14 TypeVar, 

15 Union, 

16) 

17 

18if TYPE_CHECKING: 

19 from collections.abc import Iterator 

20 

21 from astroid import bases, exceptions, nodes, transforms, util 

22 from astroid.context import InferenceContext 

23 from astroid.interpreter._import import spec 

24 

25 

26class InferenceErrorInfo(TypedDict): 

27 """Store additional Inference error information 

28 raised with StopIteration exception. 

29 """ 

30 

31 node: nodes.NodeNG 

32 context: InferenceContext | None 

33 

34 

35class AstroidManagerBrain(TypedDict): 

36 """Dictionary to store relevant information for a AstroidManager class.""" 

37 

38 astroid_cache: dict[str, nodes.Module] 

39 _mod_file_cache: dict[ 

40 tuple[str, str | None], spec.ModuleSpec | exceptions.AstroidImportError 

41 ] 

42 _failed_import_hooks: list[Callable[[str], nodes.Module]] 

43 always_load_extensions: bool 

44 optimize_ast: bool 

45 max_inferable_values: int 

46 extension_package_whitelist: set[str] 

47 _transform: transforms.TransformVisitor 

48 

49 

50# pylint: disable=consider-alternative-union-syntax 

51InferenceResult = Union["nodes.NodeNG", "util.UninferableBase", "bases.Proxy"] 

52SuccessfulInferenceResult = Union["nodes.NodeNG", "bases.Proxy"] 

53_SuccessfulInferenceResultT = TypeVar( 

54 "_SuccessfulInferenceResultT", bound=SuccessfulInferenceResult 

55) 

56_SuccessfulInferenceResultT_contra = TypeVar( 

57 "_SuccessfulInferenceResultT_contra", 

58 bound=SuccessfulInferenceResult, 

59 contravariant=True, 

60) 

61 

62ConstFactoryResult = Union[ 

63 "nodes.List", 

64 "nodes.Set", 

65 "nodes.Tuple", 

66 "nodes.Dict", 

67 "nodes.Const", 

68 "nodes.EmptyNode", 

69] 

70 

71InferBinaryOp = Callable[ 

72 [ 

73 _SuccessfulInferenceResultT, 

74 Union["nodes.AugAssign", "nodes.BinOp"], 

75 str, 

76 InferenceResult, 

77 "InferenceContext", 

78 SuccessfulInferenceResult, 

79 ], 

80 Generator[InferenceResult], 

81] 

82 

83 

84class InferFn(Protocol, Generic[_SuccessfulInferenceResultT_contra]): 

85 def __call__( 

86 self, 

87 node: _SuccessfulInferenceResultT_contra, 

88 context: InferenceContext | None = None, 

89 **kwargs: Any, 

90 ) -> Iterator[InferenceResult]: ... # pragma: no cover 

91 

92 

93class TransformFn(Protocol, Generic[_SuccessfulInferenceResultT]): 

94 def __call__( 

95 self, 

96 node: _SuccessfulInferenceResultT, 

97 infer_function: InferFn[_SuccessfulInferenceResultT] = ..., 

98 ) -> _SuccessfulInferenceResultT | None: ... # pragma: no cover