40
40
from astroid .interpreter .dunder_lookup import lookup
41
41
from astroid .interpreter .objectmodel import ClassModel , FunctionModel , ModuleModel
42
42
from 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
51
44
from astroid .nodes .scoped_nodes .mixin import ComprehensionScope , LocalsDictNodeNG
52
45
from astroid .nodes .scoped_nodes .utils import builtin_lookup
53
46
from astroid .nodes .utils import Position
60
53
61
54
if TYPE_CHECKING :
62
55
from astroid import nodes , objects
56
+ from astroid .nodes import NodeNG , Const , Arguments
63
57
from astroid .nodes ._base_nodes import LookupMixIn
64
58
65
59
@@ -353,7 +347,7 @@ def getattr(
353
347
if name in self .special_attributes and not ignore_locals and not name_in_locals :
354
348
result = [self .special_attributes .lookup (name )]
355
349
if name == "__name__" :
356
- main_const = const_factory ("__main__" )
350
+ main_const = node_classes . const_factory ("__main__" )
357
351
main_const .parent = AstroidManager ().builtins_module
358
352
result .append (main_const )
359
353
elif not ignore_locals and name_in_locals :
@@ -607,6 +601,14 @@ def _infer(
607
601
yield self
608
602
609
603
604
+ class __SyntheticRoot (Module ):
605
+ def __init__ (self ):
606
+ super ().__init__ ("__astroid_synthetic" , pure_python = False )
607
+
608
+
609
+ SYNTHETIC_ROOT = __SyntheticRoot ()
610
+
611
+
610
612
class GeneratorExp (ComprehensionScope ):
611
613
"""Class representing an :class:`ast.GeneratorExp` node.
612
614
@@ -1572,7 +1574,7 @@ def infer_call_result(
1572
1574
and len (self .args .args ) == 1
1573
1575
and self .args .vararg is not None
1574
1576
):
1575
- if isinstance (caller .args , Arguments ):
1577
+ if isinstance (caller .args , node_classes . Arguments ):
1576
1578
assert caller .args .args is not None
1577
1579
metaclass = next (caller .args .args [0 ].infer (context ), None )
1578
1580
elif isinstance (caller .args , list ):
@@ -1583,17 +1585,13 @@ def infer_call_result(
1583
1585
)
1584
1586
if isinstance (metaclass , ClassDef ):
1585
1587
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 :]]
1597
1595
except StopIteration as e :
1598
1596
raise InferenceError (node = caller .args [1 :], context = context ) from e
1599
1597
new_class = ClassDef (
@@ -1602,7 +1600,7 @@ def infer_call_result(
1602
1600
col_offset = 0 ,
1603
1601
end_lineno = 0 ,
1604
1602
end_col_offset = 0 ,
1605
- parent = AstroidManager (). synthetic_root ,
1603
+ parent = SYNTHETIC_ROOT ,
1606
1604
)
1607
1605
new_class .hide = True
1608
1606
new_class .postinit (
@@ -2831,7 +2829,7 @@ def _inferred_bases(self, context: InferenceContext | None = None):
2831
2829
baseobj = next (
2832
2830
b
2833
2831
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 )
2835
2833
)
2836
2834
except (InferenceError , StopIteration ):
2837
2835
continue
0 commit comments