Skip to content

Commit

Permalink
create an "adhoc" module for "artificial" nodes
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
temyurchenko authored and DanielNoord committed Sep 10, 2024
1 parent 6ec2d40 commit b6d52d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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''"),
Expand Down
4 changes: 4 additions & 0 deletions astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit b6d52d3

Please sign in to comment.