4040from astroid .interpreter .dunder_lookup import lookup
4141from astroid .interpreter .objectmodel import ClassModel , FunctionModel , ModuleModel
4242from astroid .manager import AstroidManager
43- from astroid .nodes import (
44- Arguments ,
45- Const ,
46- NodeNG ,
47- _base_nodes ,
48- const_factory ,
49- node_classes ,
50- )
43+ from astroid .nodes import _base_nodes , node_classes
5144from astroid .nodes .scoped_nodes .mixin import ComprehensionScope , LocalsDictNodeNG
5245from astroid .nodes .scoped_nodes .utils import builtin_lookup
5346from astroid .nodes .utils import Position
6053
6154if TYPE_CHECKING :
6255 from astroid import nodes , objects
56+ from astroid .nodes import NodeNG , Const , Arguments
6357 from astroid .nodes ._base_nodes import LookupMixIn
6458
6559
@@ -353,7 +347,7 @@ def getattr(
353347 if name in self .special_attributes and not ignore_locals and not name_in_locals :
354348 result = [self .special_attributes .lookup (name )]
355349 if name == "__name__" :
356- main_const = const_factory ("__main__" )
350+ main_const = node_classes . const_factory ("__main__" )
357351 main_const .parent = AstroidManager ().builtins_module
358352 result .append (main_const )
359353 elif not ignore_locals and name_in_locals :
@@ -607,6 +601,14 @@ def _infer(
607601 yield self
608602
609603
604+ class __SyntheticRoot (Module ):
605+ def __init__ (self ):
606+ super ().__init__ ("__astroid_synthetic" , pure_python = False )
607+
608+
609+ SYNTHETIC_ROOT = __SyntheticRoot ()
610+
611+
610612class GeneratorExp (ComprehensionScope ):
611613 """Class representing an :class:`ast.GeneratorExp` node.
612614
@@ -1572,7 +1574,7 @@ def infer_call_result(
15721574 and len (self .args .args ) == 1
15731575 and self .args .vararg is not None
15741576 ):
1575- if isinstance (caller .args , Arguments ):
1577+ if isinstance (caller .args , node_classes . Arguments ):
15761578 assert caller .args .args is not None
15771579 metaclass = next (caller .args .args [0 ].infer (context ), None )
15781580 elif isinstance (caller .args , list ):
@@ -1583,17 +1585,13 @@ def infer_call_result(
15831585 )
15841586 if isinstance (metaclass , ClassDef ):
15851587 try :
1586- class_bases = [
1587- # Find the first non-None inferred base value
1588- next (
1589- b
1590- for b in arg .infer (
1591- context = context .clone () if context else context
1592- )
1593- if not (isinstance (b , Const ) and b .value is None )
1594- )
1595- for arg in caller .args [1 :]
1596- ]
1588+ # Find the first non-None inferred base value
1589+ get_base = lambda arg : next (
1590+ b
1591+ for b in arg .infer (context = context .clone () if context else None )
1592+ if not (isinstance (b , node_classes .Const ) and b .value is None )
1593+ )
1594+ class_bases = [get_base (arg ) for arg in caller .args [1 :]]
15971595 except StopIteration as e :
15981596 raise InferenceError (node = caller .args [1 :], context = context ) from e
15991597 new_class = ClassDef (
@@ -1602,7 +1600,7 @@ def infer_call_result(
16021600 col_offset = 0 ,
16031601 end_lineno = 0 ,
16041602 end_col_offset = 0 ,
1605- parent = AstroidManager (). synthetic_root ,
1603+ parent = SYNTHETIC_ROOT ,
16061604 )
16071605 new_class .hide = True
16081606 new_class .postinit (
@@ -2831,7 +2829,7 @@ def _inferred_bases(self, context: InferenceContext | None = None):
28312829 baseobj = next (
28322830 b
28332831 for b in stmt .infer (context = context .clone ())
2834- if not (isinstance (b , Const ) and b .value is None )
2832+ if not (isinstance (b , node_classes . Const ) and b .value is None )
28352833 )
28362834 except (InferenceError , StopIteration ):
28372835 continue
0 commit comments