summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--astroid/brain/brain_builtin_inference.py4
-rw-r--r--astroid/helpers.py2
-rw-r--r--astroid/interpreter/objectmodel.py9
-rw-r--r--astroid/manager.py4
-rw-r--r--astroid/node_classes.py2
-rw-r--r--astroid/objects.py4
-rw-r--r--astroid/scoped_nodes.py2
-rw-r--r--astroid/tests/unittest_inference.py22
8 files changed, 34 insertions, 15 deletions
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py
index 2655095a..21dd6872 100644
--- a/astroid/brain/brain_builtin_inference.py
+++ b/astroid/brain/brain_builtin_inference.py
@@ -94,9 +94,7 @@ def _extend_str(class_node, rvalue):
def _extend_builtins(class_transforms):
- from astroid.bases import BUILTINS
-
- builtin_ast = MANAGER.astroid_cache[BUILTINS]
+ builtin_ast = MANAGER.builtins_module
for class_name, transform in class_transforms.items():
transform(builtin_ast[class_name])
diff --git a/astroid/helpers.py b/astroid/helpers.py
index e58d1919..edbb205c 100644
--- a/astroid/helpers.py
+++ b/astroid/helpers.py
@@ -46,7 +46,7 @@ def _function_type(function, builtins):
def _object_type(node, context=None):
astroid_manager = manager.AstroidManager()
- builtins = astroid_manager.astroid_cache[BUILTINS]
+ builtins = astroid_manager.builtins_module
context = context or contextmod.InferenceContext()
for inferred in node.infer(context=context):
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index c9da8023..f031022f 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -25,7 +25,6 @@ attribute. Thus the model can be viewed as a special part of the lookup
mechanism.
"""
-import builtins
import itertools
import pprint
import os
@@ -119,7 +118,7 @@ class ObjectModel:
class ModuleModel(ObjectModel):
def _builtins(self):
- builtins_ast_module = astroid.MANAGER.astroid_cache[builtins.__name__]
+ builtins_ast_module = astroid.MANAGER.builtins_module
return builtins_ast_module.special_attributes.lookup("__dict__")
@property
@@ -540,7 +539,7 @@ class GeneratorModel(FunctionModel):
def __new__(cls, *args, **kwargs):
# Append the values from the GeneratorType unto this object.
ret = super(GeneratorModel, cls).__new__(cls, *args, **kwargs)
- generator = astroid.MANAGER.astroid_cache[builtins.__name__]["generator"]
+ generator = astroid.MANAGER.builtins_module["generator"]
for name, values in generator.locals.items():
method = values[0]
patched = lambda cls, meth=method: meth
@@ -566,7 +565,7 @@ class AsyncGeneratorModel(GeneratorModel):
def __new__(cls, *args, **kwargs):
# Append the values from the AGeneratorType unto this object.
ret = super().__new__(cls, *args, **kwargs)
- astroid_builtins = astroid.MANAGER.astroid_cache[builtins.__name__]
+ astroid_builtins = astroid.MANAGER.builtins_module
generator = astroid_builtins.get("async_generator")
if generator is None:
# Make it backward compatible.
@@ -612,7 +611,7 @@ class ExceptionInstanceModel(InstanceModel):
@property
def attr___traceback__(self):
- builtins_ast_module = astroid.MANAGER.astroid_cache[builtins.__name__]
+ builtins_ast_module = astroid.MANAGER.builtins_module
traceback_type = builtins_ast_module[types.TracebackType.__name__]
return traceback_type.instantiate_class()
diff --git a/astroid/manager.py b/astroid/manager.py
index f05588ae..c7295b57 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -60,6 +60,10 @@ class AstroidManager:
self.unregister_transform = self._transform.unregister_transform
self.max_inferable_values = 100
+ @property
+ def builtins_module(self):
+ return self.astroid_cache["builtins"]
+
def visit_transforms(self, node):
"""Visit the transforms and apply them to the given *node*."""
return self._transform.visit(node)
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index fe6f6bbb..4e5f5612 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -3874,7 +3874,7 @@ class Slice(NodeNG):
@decorators.cachedproperty
def _proxied(self):
- builtins = MANAGER.astroid_cache[BUILTINS]
+ builtins = MANAGER.builtins_module
return builtins.getattr("slice")[0]
def pytype(self):
diff --git a/astroid/objects.py b/astroid/objects.py
index 1a071b2c..b68d3596 100644
--- a/astroid/objects.py
+++ b/astroid/objects.py
@@ -43,7 +43,7 @@ class FrozenSet(node_classes._BaseContainer):
@decorators.cachedproperty
def _proxied(self): # pylint: disable=method-hidden
- ast_builtins = MANAGER.astroid_cache[BUILTINS]
+ ast_builtins = MANAGER.builtins_module
return ast_builtins.getattr("frozenset")[0]
@@ -114,7 +114,7 @@ class Super(node_classes.NodeNG):
@decorators.cachedproperty
def _proxied(self):
- ast_builtins = MANAGER.astroid_cache[BUILTINS]
+ ast_builtins = MANAGER.builtins_module
return ast_builtins.getattr("super")[0]
def pytype(self):
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 13721adc..5457e1ff 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -2134,7 +2134,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement
# inside this class.
lookup_upper_frame = (
isinstance(node.parent, node_classes.Decorators)
- and name in MANAGER.astroid_cache[builtins.__name__]
+ and name in MANAGER.builtins_module
)
if (
any(node == base or base.parent_of(node) for base in self.bases)
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index 420e528c..9592b437 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -31,10 +31,10 @@ from unittest.mock import patch
import pytest
-from astroid import InferenceError, builder, nodes
+from astroid import InferenceError, builder, nodes, MANAGER
from astroid.builder import parse, extract_node
from astroid.inference import infer_end as inference_infer_end
-from astroid.bases import Instance, BoundMethod, UnboundMethod, BUILTINS
+from astroid.bases import Instance, BoundMethod, UnboundMethod, BUILTINS, Generator
from astroid import arguments
from astroid import decorators as decoratorsmod
from astroid import exceptions
@@ -5072,5 +5072,23 @@ def test_inferred_sequence_unpacking_works():
assert [value.value for value in inferred.elts] == [1, 2]
+def test_separate_cache_object():
+ code = extract_node(
+ """
+ def loop_gen():
+ for y in test_gen():
+ yield y
+
+ def test_gen():
+ yield "yield"
+ return
+ test_gen()
+ """
+ )
+ MANAGER.clear_cache()
+ inferred = next(code.infer())
+ assert isinstance(inferred, Generator)
+
+
if __name__ == "__main__":
unittest.main()