Skip to content

Commit b6d52d3

Browse files
temyurchenkoDanielNoord
authored andcommitted
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).
1 parent 6ec2d40 commit b6d52d3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

astroid/brain/brain_builtin_inference.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from astroid.inference_tip import inference_tip
2525
from astroid.manager import AstroidManager
2626
from astroid.nodes import scoped_nodes
27+
from astroid.raw_building import build_module
2728
from astroid.typing import (
2829
ConstFactoryResult,
2930
InferenceResult,
@@ -164,6 +165,8 @@ def _extend_builtins(class_transforms):
164165

165166
def on_bootstrap():
166167
"""Called by astroid_bootstrapping()."""
168+
AstroidManager().cache_module(build_module("__astroid_adhoc"))
169+
167170
_extend_builtins(
168171
{
169172
"bytes": partial(_extend_string_class, code=BYTES_CLASS, rvalue="b''"),

astroid/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def unregister_transform(self):
115115
def builtins_module(self) -> nodes.Module:
116116
return self.astroid_cache["builtins"]
117117

118+
@property
119+
def adhoc_module(self) -> nodes.Module:
120+
return self.astroid_cache["__astroid_adhoc"]
121+
118122
@property
119123
def prefer_stubs(self) -> bool:
120124
return AstroidManager.brain["prefer_stubs"]

0 commit comments

Comments
 (0)