35
35
from astroid.interpreter import dunder_lookup
36
36
from astroid import protocols
37
37
from astroid import util
38
+ cimport cython
38
39
39
40
40
41
MANAGER = manager.AstroidManager()
41
42
42
43
43
44
# .infer method ###############################################################
44
45
45
-
46
+ @ cython.binding ( True )
46
47
def infer_end (self , context = None ):
47
48
""" inference's end for node such as Module, ClassDef, FunctionDef,
48
49
Const...
@@ -78,6 +79,7 @@ def _infer_sequence_helper(node, context=None):
78
79
79
80
@decorators.raise_if_nothing_inferred
80
81
@decorators.path_wrapper
82
+ @ cython.binding (True )
81
83
def infer_sequence (self , context = None ):
82
84
if not any (isinstance (e, nodes.Starred) for e in self .elts):
83
85
yield self
@@ -93,6 +95,7 @@ def infer_sequence(self, context=None):
93
95
nodes.Set._infer = infer_sequence
94
96
95
97
98
+ @ cython.binding (True )
96
99
def infer_map (self , context = None ):
97
100
if not any (isinstance (k, nodes.DictUnpack) for k, _ in self .items):
98
101
yield self
@@ -171,6 +174,7 @@ def _higher_function_scope(node):
171
174
return current.parent
172
175
return None
173
176
177
+ @ cython.binding (True )
174
178
def infer_name (self , context = None ):
175
179
""" infer a Name: use name lookup rules"""
176
180
frame, stmts = self .lookup(self .name)
@@ -190,14 +194,13 @@ def infer_name(self, context=None):
190
194
return bases._infer_stmts(stmts, context, frame)
191
195
192
196
# pylint: disable=no-value-for-parameter
193
- nodes .Name ._infer = decorators .raise_if_nothing_inferred (
194
- decorators .path_wrapper (infer_name )
195
- )
197
+ nodes.Name._infer = decorators.raise_if_nothing_inferred(decorators.path_wrapper(infer_name))
196
198
nodes.AssignName.infer_lhs = infer_name # won't work with a path wrapper
197
199
198
200
199
201
@decorators.raise_if_nothing_inferred
200
202
@decorators.path_wrapper
203
+ @ cython.binding (True )
201
204
def infer_call (self , context = None ):
202
205
""" infer a Call node by trying to guess what the function returns"""
203
206
callcontext = context.clone()
@@ -226,6 +229,7 @@ def infer_call(self, context=None):
226
229
227
230
@decorators.raise_if_nothing_inferred
228
231
@decorators.path_wrapper
232
+ @ cython.binding (True )
229
233
def infer_import (self , context = None , asname = True ):
230
234
""" infer an Import node: return the imported module/object"""
231
235
name = context.lookupname
@@ -247,6 +251,7 @@ def infer_import(self, context=None, asname=True):
247
251
nodes.Import._infer = infer_import
248
252
249
253
254
+ @ cython.binding (True )
250
255
def infer_name_module (self , name ):
251
256
context = contextmod.InferenceContext()
252
257
context.lookupname = name
@@ -256,6 +261,7 @@ def infer_name_module(self, name):
256
261
257
262
@decorators.raise_if_nothing_inferred
258
263
@decorators.path_wrapper
264
+ @ cython.binding (True )
259
265
def infer_import_from (self , context = None , asname = True ):
260
266
""" infer a ImportFrom node: return the imported module/object"""
261
267
name = context.lookupname
@@ -288,6 +294,7 @@ def infer_import_from(self, context=None, asname=True):
288
294
289
295
290
296
@decorators.raise_if_nothing_inferred
297
+ @ cython.binding (True )
291
298
def infer_attribute (self , context = None ):
292
299
""" infer an Attribute node by using getattr on the associated object"""
293
300
for owner in self .expr.infer(context):
@@ -325,6 +332,7 @@ def infer_attribute(self, context=None):
325
332
326
333
@decorators.raise_if_nothing_inferred
327
334
@decorators.path_wrapper
335
+ @ cython.binding (True )
328
336
def infer_global (self , context = None ):
329
337
if context.lookupname is None :
330
338
raise exceptions.InferenceError(node = self , context = context)
@@ -345,6 +353,7 @@ def infer_global(self, context=None):
345
353
346
354
347
355
@decorators.raise_if_nothing_inferred
356
+ @ cython.binding (True )
348
357
def infer_subscript (self , context = None ):
349
358
""" Inference for subscripts
350
359
@@ -407,6 +416,7 @@ def infer_subscript(self, context=None):
407
416
408
417
@decorators.raise_if_nothing_inferred
409
418
@decorators.path_wrapper
419
+ @ cython.binding (True )
410
420
def _infer_boolop (self , context = None ):
411
421
""" Infer a boolean operation (and / or / not).
412
422
@@ -462,6 +472,7 @@ def _infer_boolop(self, context=None):
462
472
463
473
# UnaryOp, BinOp and AugAssign inferences
464
474
475
+ @ cython.binding (True )
465
476
def _filter_operation_errors (self , infer_callable , context , error ):
466
477
for result in infer_callable(self , context):
467
478
if isinstance (result, error):
@@ -473,6 +484,7 @@ def _filter_operation_errors(self, infer_callable, context, error):
473
484
yield result
474
485
475
486
487
+ @ cython.binding (True )
476
488
def _infer_unaryop (self , context = None ):
477
489
""" Infer what an UnaryOp should return when evaluated."""
478
490
for operand in self .operand.infer(context):
@@ -529,6 +541,7 @@ def _infer_unaryop(self, context=None):
529
541
530
542
@decorators.raise_if_nothing_inferred
531
543
@decorators.path_wrapper
544
+ @ cython.binding (True )
532
545
def infer_unaryop (self , context = None ):
533
546
""" Infer what an UnaryOp should return when evaluated."""
534
547
yield from _filter_operation_errors(self , _infer_unaryop, context,
@@ -711,6 +724,7 @@ def _infer_binary_operation(left, right, binary_opnode, context, flow_factory):
711
724
yield util.BadBinaryOperationMessage(left_type, binary_opnode.op, right_type)
712
725
713
726
727
+ @ cython.binding (True )
714
728
def _infer_binop (self , context ):
715
729
""" Binary operation inference logic."""
716
730
if context is None :
@@ -745,6 +759,7 @@ def _infer_binop(self, context):
745
759
746
760
@decorators.yes_if_nothing_inferred
747
761
@decorators.path_wrapper
762
+ @ cython.binding (True )
748
763
def infer_binop (self , context = None ):
749
764
return _filter_operation_errors(self , _infer_binop, context,
750
765
util.BadBinaryOperationMessage)
@@ -753,6 +768,7 @@ def infer_binop(self, context=None):
753
768
nodes.BinOp._infer = infer_binop
754
769
755
770
771
+ @ cython.binding (True )
756
772
def _infer_augassign (self , context = None ):
757
773
""" Inference logic for augmented binary operations."""
758
774
if context is None :
@@ -779,6 +795,7 @@ def _infer_augassign(self, context=None):
779
795
780
796
@decorators.raise_if_nothing_inferred
781
797
@decorators.path_wrapper
798
+ @ cython.binding (True )
782
799
def infer_augassign (self , context = None ):
783
800
return _filter_operation_errors(self , _infer_augassign, context,
784
801
util.BadBinaryOperationMessage)
@@ -791,6 +808,7 @@ def infer_augassign(self, context=None):
791
808
792
809
@decorators.raise_if_nothing_inferred
793
810
@decorators.path_wrapper
811
+ @ cython.binding (True )
794
812
def infer_arguments (self , context = None ):
795
813
name = context.lookupname
796
814
if name is None :
@@ -801,6 +819,7 @@ def infer_arguments(self, context=None):
801
819
802
820
@decorators.raise_if_nothing_inferred
803
821
@decorators.path_wrapper
822
+ @ cython.binding (True )
804
823
def infer_assign (self , context = None ):
805
824
""" infer a AssignName/AssignAttr: need to inspect the RHS part of the
806
825
assign node
@@ -819,6 +838,7 @@ def infer_assign(self, context=None):
819
838
820
839
@decorators.raise_if_nothing_inferred
821
840
@decorators.path_wrapper
841
+ @ cython.binding (True )
822
842
def infer_empty_node (self , context = None ):
823
843
if not self .has_underlying_object():
824
844
yield util.Uninferable
@@ -832,12 +852,14 @@ def infer_empty_node(self, context=None):
832
852
833
853
@decorators.raise_if_nothing_inferred
834
854
@decorators.path_wrapper
855
+ @ cython.binding (True )
835
856
def infer_index (self , context = None ):
836
857
return self .value.infer(context)
837
858
nodes.Index._infer = infer_index
838
859
839
860
# TODO: move directly into bases.Instance when the dependency hell
840
861
# will be solved.
862
+ @ cython.binding (True )
841
863
def instance_getitem (self , index , context = None ):
842
864
# Rewrap index to Const for this case
843
865
new_context = contextmod.bind_context_to_node(context, self )
0 commit comments