Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/astroid/__init__.py: 100%
22 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:53 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:53 +0000
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
5"""Python Abstract Syntax Tree New Generation.
7The aim of this module is to provide a common base representation of
8python source code for projects such as pychecker, pyreverse,
9pylint... Well, actually the development of this library is essentially
10governed by pylint's needs.
12It mimics the class defined in the python's _ast module with some
13additional methods and attributes. New nodes instances are not fully
14compatible with python's _ast.
16Instance attributes are added by a
17builder object, which can either generate extended ast (let's call
18them astroid ;) by visiting an existent ast tree or by inspecting living
19object. Methods are added by monkey patching ast classes.
21Main modules are:
23* nodes and scoped_nodes for more information about methods and
24 attributes added to different node classes
26* the manager contains a high level object to get astroid trees from
27 source files and living objects. It maintains a cache of previously
28 constructed tree for quick access
30* builder contains the class responsible to build astroid trees
31"""
33import functools
34import tokenize
35from importlib import import_module
37# isort: off
38# We have an isort: off on '__version__' because of a circular import in nodes.
39from astroid.nodes import node_classes, scoped_nodes
41# isort: on
43from astroid import inference, raw_building
44from astroid.__pkginfo__ import __version__, version
45from astroid.astroid_manager import MANAGER
46from astroid.bases import BaseInstance, BoundMethod, Instance, UnboundMethod
47from astroid.brain.helpers import register_module_extender
48from astroid.builder import extract_node, parse
49from astroid.const import BRAIN_MODULES_DIRECTORY, PY310_PLUS, Context
50from astroid.exceptions import (
51 AstroidBuildingError,
52 AstroidBuildingException,
53 AstroidError,
54 AstroidImportError,
55 AstroidIndexError,
56 AstroidSyntaxError,
57 AstroidTypeError,
58 AstroidValueError,
59 AttributeInferenceError,
60 BinaryOperationError,
61 DuplicateBasesError,
62 InconsistentMroError,
63 InferenceError,
64 InferenceOverwriteError,
65 MroError,
66 NameInferenceError,
67 NoDefault,
68 NotFoundError,
69 OperationError,
70 ParentMissingError,
71 ResolveError,
72 StatementMissing,
73 SuperArgumentTypeError,
74 SuperError,
75 TooManyLevelsError,
76 UnaryOperationError,
77 UnresolvableName,
78 UseInferenceDefault,
79)
80from astroid.inference_tip import _inference_tip_cached, inference_tip
81from astroid.objects import ExceptionInstance
83# isort: off
84# It's impossible to import from astroid.nodes with a wildcard, because
85# there is a cyclic import that prevent creating an __all__ in astroid/nodes
86# and we need astroid/scoped_nodes and astroid/node_classes to work. So
87# importing with a wildcard would clash with astroid/nodes/scoped_nodes
88# and astroid/nodes/node_classes.
89from astroid.nodes import (
90 CONST_CLS,
91 AnnAssign,
92 Arguments,
93 Assert,
94 Assign,
95 AssignAttr,
96 AssignName,
97 AsyncFor,
98 AsyncFunctionDef,
99 AsyncWith,
100 Attribute,
101 AugAssign,
102 Await,
103 BinOp,
104 BoolOp,
105 Break,
106 Call,
107 ClassDef,
108 Compare,
109 Comprehension,
110 ComprehensionScope,
111 Const,
112 Continue,
113 Decorators,
114 DelAttr,
115 Delete,
116 DelName,
117 Dict,
118 DictComp,
119 DictUnpack,
120 EmptyNode,
121 EvaluatedObject,
122 ExceptHandler,
123 Expr,
124 For,
125 FormattedValue,
126 FunctionDef,
127 GeneratorExp,
128 Global,
129 If,
130 IfExp,
131 Import,
132 ImportFrom,
133 JoinedStr,
134 Keyword,
135 Lambda,
136 List,
137 ListComp,
138 Match,
139 MatchAs,
140 MatchCase,
141 MatchClass,
142 MatchMapping,
143 MatchOr,
144 MatchSequence,
145 MatchSingleton,
146 MatchStar,
147 MatchValue,
148 Module,
149 Name,
150 NamedExpr,
151 NodeNG,
152 Nonlocal,
153 Pass,
154 Raise,
155 Return,
156 Set,
157 SetComp,
158 Slice,
159 Starred,
160 Subscript,
161 TryExcept,
162 TryFinally,
163 TryStar,
164 Tuple,
165 UnaryOp,
166 Unknown,
167 While,
168 With,
169 Yield,
170 YieldFrom,
171 are_exclusive,
172 builtin_lookup,
173 unpack_infer,
174 function_to_method,
175)
177# isort: on
179from astroid.util import Uninferable
181# Performance hack for tokenize. See https://bugs.python.org/issue43014
182# Adapted from https://github.com/PyCQA/pycodestyle/pull/993
183if (
184 not PY310_PLUS
185 and callable(getattr(tokenize, "_compile", None))
186 and getattr(tokenize._compile, "__wrapped__", None) is None # type: ignore[attr-defined]
187):
188 tokenize._compile = functools.lru_cache(tokenize._compile) # type: ignore[attr-defined]
190# load brain plugins
191for module in BRAIN_MODULES_DIRECTORY.iterdir():
192 if module.suffix == ".py":
193 import_module(f"astroid.brain.{module.stem}")