typing.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. import sys
  6. from typing import TYPE_CHECKING, Any, Callable, Generator, TypeVar, Union
  7. if TYPE_CHECKING:
  8. from astroid import bases, exceptions, nodes, transforms, util
  9. from astroid.context import InferenceContext
  10. from astroid.interpreter._import import spec
  11. if sys.version_info >= (3, 8):
  12. from typing import TypedDict
  13. else:
  14. from typing_extensions import TypedDict
  15. _NodesT = TypeVar("_NodesT", bound="nodes.NodeNG")
  16. class InferenceErrorInfo(TypedDict):
  17. """Store additional Inference error information
  18. raised with StopIteration exception.
  19. """
  20. node: nodes.NodeNG
  21. context: InferenceContext | None
  22. InferFn = Callable[..., Any]
  23. class AstroidManagerBrain(TypedDict):
  24. """Dictionary to store relevant information for a AstroidManager class."""
  25. astroid_cache: dict[str, nodes.Module]
  26. _mod_file_cache: dict[
  27. tuple[str, str | None], spec.ModuleSpec | exceptions.AstroidImportError
  28. ]
  29. _failed_import_hooks: list[Callable[[str], nodes.Module]]
  30. always_load_extensions: bool
  31. optimize_ast: bool
  32. extension_package_whitelist: set[str]
  33. _transform: transforms.TransformVisitor
  34. InferenceResult = Union["nodes.NodeNG", "util.UninferableBase", "bases.Proxy"]
  35. SuccessfulInferenceResult = Union["nodes.NodeNG", "bases.Proxy"]
  36. ConstFactoryResult = Union[
  37. "nodes.List",
  38. "nodes.Set",
  39. "nodes.Tuple",
  40. "nodes.Dict",
  41. "nodes.Const",
  42. "nodes.EmptyNode",
  43. ]
  44. InferBinaryOp = Callable[
  45. [
  46. Union[_NodesT, "bases.Instance"],
  47. Union["nodes.AugAssign", "nodes.BinOp"],
  48. str,
  49. InferenceResult,
  50. "InferenceContext",
  51. SuccessfulInferenceResult,
  52. ],
  53. Generator[InferenceResult, None, None],
  54. ]