diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2022-02-26 19:56:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-26 19:56:19 +0100 |
commit | a62f37ddae2d6fdb6f8ec0f2e5b6a0a41e5f883e (patch) | |
tree | 4531fff0b7ef02cb35146bb65482163bbe916625 /astroid/__init__.py | |
parent | 514c832a6957c7589aa3e14973189e2e245de961 (diff) | |
download | astroid-git-a62f37ddae2d6fdb6f8ec0f2e5b6a0a41e5f883e.tar.gz |
Add position attribute for nodes (#1393)
Diffstat (limited to 'astroid/__init__.py')
-rw-r--r-- | astroid/__init__.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/astroid/__init__.py b/astroid/__init__.py index b2f2c817..c94b24c7 100644 --- a/astroid/__init__.py +++ b/astroid/__init__.py @@ -43,6 +43,8 @@ Main modules are: * builder contains the class responsible to build astroid trees """ +import functools +import tokenize from importlib import import_module from pathlib import Path @@ -60,7 +62,7 @@ from astroid.astroid_manager import MANAGER from astroid.bases import BaseInstance, BoundMethod, Instance, UnboundMethod from astroid.brain.helpers import register_module_extender from astroid.builder import extract_node, parse -from astroid.const import Context, Del, Load, Store +from astroid.const import PY310_PLUS, Context, Del, Load, Store from astroid.exceptions import * from astroid.inference_tip import _inference_tip_cached, inference_tip from astroid.objects import ExceptionInstance @@ -165,6 +167,15 @@ from astroid.nodes import ( # pylint: disable=redefined-builtin (Ellipsis) from astroid.util import Uninferable +# Performance hack for tokenize. See https://bugs.python.org/issue43014 +# Adapted from https://github.com/PyCQA/pycodestyle/pull/993 +if ( + not PY310_PLUS + and callable(getattr(tokenize, "_compile", None)) + and getattr(tokenize._compile, "__wrapped__", None) is None # type: ignore[attr-defined] +): + tokenize._compile = functools.lru_cache()(tokenize._compile) # type: ignore[attr-defined] + # load brain plugins ASTROID_INSTALL_DIRECTORY = Path(__file__).parent BRAIN_MODULES_DIRECTORY = ASTROID_INSTALL_DIRECTORY / "brain" |