__init__.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Copyright (c) 2006-2013, 2015 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2014 Google, Inc.
  3. # Copyright (c) 2014 Eevee (Alex Munroe) <amunroe@yelp.com>
  4. # Copyright (c) 2015-2016, 2018, 2020 Claudiu Popa <pcmanticore@gmail.com>
  5. # Copyright (c) 2015-2016 Ceridwen <ceridwenv@gmail.com>
  6. # Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
  7. # Copyright (c) 2016 Moises Lopez <moylop260@vauxoo.com>
  8. # Copyright (c) 2018 Bryce Guinta <bryce.paul.guinta@gmail.com>
  9. # Copyright (c) 2019 Nick Drozd <nicholasdrozd@gmail.com>
  10. # Copyright (c) 2020-2021 hippo91 <guillaume.peillex@gmail.com>
  11. # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
  12. # Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
  13. # Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  14. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  15. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  16. """Python Abstract Syntax Tree New Generation
  17. The aim of this module is to provide a common base representation of
  18. python source code for projects such as pychecker, pyreverse,
  19. pylint... Well, actually the development of this library is essentially
  20. governed by pylint's needs.
  21. It extends class defined in the python's _ast module with some
  22. additional methods and attributes. Instance attributes are added by a
  23. builder object, which can either generate extended ast (let's call
  24. them astroid ;) by visiting an existent ast tree or by inspecting living
  25. object. Methods are added by monkey patching ast classes.
  26. Main modules are:
  27. * nodes and scoped_nodes for more information about methods and
  28. attributes added to different node classes
  29. * the manager contains a high level object to get astroid trees from
  30. source files and living objects. It maintains a cache of previously
  31. constructed tree for quick access
  32. * builder contains the class responsible to build astroid trees
  33. """
  34. from importlib import import_module
  35. from pathlib import Path
  36. # isort: off
  37. # We have an isort: off on '__version__' because the packaging need to access
  38. # the version before the dependencies are installed (in particular 'wrapt'
  39. # that is imported in astroid.inference)
  40. from astroid.__pkginfo__ import __version__, version
  41. from astroid.nodes import node_classes, scoped_nodes
  42. # isort: on
  43. from astroid import inference, raw_building
  44. from astroid.astroid_manager import MANAGER
  45. from astroid.bases import BaseInstance, BoundMethod, Instance, UnboundMethod
  46. from astroid.brain.helpers import register_module_extender
  47. from astroid.builder import extract_node, parse
  48. from astroid.const import Context, Del, Load, Store
  49. from astroid.exceptions import *
  50. from astroid.inference_tip import _inference_tip_cached, inference_tip
  51. from astroid.objects import ExceptionInstance
  52. # isort: off
  53. # It's impossible to import from astroid.nodes with a wildcard, because
  54. # there is a cyclic import that prevent creating an __all__ in astroid/nodes
  55. # and we need astroid/scoped_nodes and astroid/node_classes to work. So
  56. # importing with a wildcard would clash with astroid/nodes/scoped_nodes
  57. # and astroid/nodes/node_classes.
  58. from astroid.nodes import ( # pylint: disable=redefined-builtin (Ellipsis)
  59. CONST_CLS,
  60. AnnAssign,
  61. Arguments,
  62. Assert,
  63. Assign,
  64. AssignAttr,
  65. AssignName,
  66. AsyncFor,
  67. AsyncFunctionDef,
  68. AsyncWith,
  69. Attribute,
  70. AugAssign,
  71. Await,
  72. BinOp,
  73. BoolOp,
  74. Break,
  75. Call,
  76. ClassDef,
  77. Compare,
  78. Comprehension,
  79. ComprehensionScope,
  80. Const,
  81. Continue,
  82. Decorators,
  83. DelAttr,
  84. Delete,
  85. DelName,
  86. Dict,
  87. DictComp,
  88. DictUnpack,
  89. Ellipsis,
  90. EmptyNode,
  91. EvaluatedObject,
  92. ExceptHandler,
  93. Expr,
  94. ExtSlice,
  95. For,
  96. FormattedValue,
  97. FunctionDef,
  98. GeneratorExp,
  99. Global,
  100. If,
  101. IfExp,
  102. Import,
  103. ImportFrom,
  104. Index,
  105. JoinedStr,
  106. Keyword,
  107. Lambda,
  108. List,
  109. ListComp,
  110. Match,
  111. MatchAs,
  112. MatchCase,
  113. MatchClass,
  114. MatchMapping,
  115. MatchOr,
  116. MatchSequence,
  117. MatchSingleton,
  118. MatchStar,
  119. MatchValue,
  120. Module,
  121. Name,
  122. NamedExpr,
  123. NodeNG,
  124. Nonlocal,
  125. Pass,
  126. Raise,
  127. Return,
  128. Set,
  129. SetComp,
  130. Slice,
  131. Starred,
  132. Subscript,
  133. TryExcept,
  134. TryFinally,
  135. Tuple,
  136. UnaryOp,
  137. Unknown,
  138. While,
  139. With,
  140. Yield,
  141. YieldFrom,
  142. are_exclusive,
  143. builtin_lookup,
  144. unpack_infer,
  145. function_to_method,
  146. )
  147. # isort: on
  148. from astroid.util import Uninferable
  149. # load brain plugins
  150. ASTROID_INSTALL_DIRECTORY = Path(__file__).parent
  151. BRAIN_MODULES_DIRECTORY = ASTROID_INSTALL_DIRECTORY / "brain"
  152. for module in BRAIN_MODULES_DIRECTORY.iterdir():
  153. if module.suffix == ".py":
  154. import_module(f"astroid.brain.{module.stem}")