From b6d52d321777c95bf7947e9352e8d02d709c70e4 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Mon, 9 Sep 2024 11:04:34 -0700 Subject: [PATCH] create an "adhoc" module for "artificial" nodes the module is specifically for nodes that are not based in the real syntactic tree, but created "ad-hoc", for example, new namedtuple classes that we create (see brain_namedtuple_enum). This is the base for future changes on replacing non-module roots (with the adhoc module or something more approriate). --- astroid/brain/brain_builtin_inference.py | 3 +++ astroid/manager.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index fcaa912ed8..476620bd81 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -24,6 +24,7 @@ from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager from astroid.nodes import scoped_nodes +from astroid.raw_building import build_module from astroid.typing import ( ConstFactoryResult, InferenceResult, @@ -164,6 +165,8 @@ def _extend_builtins(class_transforms): def on_bootstrap(): """Called by astroid_bootstrapping().""" + AstroidManager().cache_module(build_module("__astroid_adhoc")) + _extend_builtins( { "bytes": partial(_extend_string_class, code=BYTES_CLASS, rvalue="b''"), diff --git a/astroid/manager.py b/astroid/manager.py index 7206be616a..7ed4525b8c 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -115,6 +115,10 @@ def unregister_transform(self): def builtins_module(self) -> nodes.Module: return self.astroid_cache["builtins"] + @property + def adhoc_module(self) -> nodes.Module: + return self.astroid_cache["__astroid_adhoc"] + @property def prefer_stubs(self) -> bool: return AstroidManager.brain["prefer_stubs"]