Skip to content

Commit c9fef18

Browse files
committed
fixed some/all of the dynamic binding
1 parent dcc00c6 commit c9fef18

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

astroid/inference.py renamed to astroid/inference.pyx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
from astroid.interpreter import dunder_lookup
3636
from astroid import protocols
3737
from astroid import util
38+
cimport cython
3839

3940

4041
MANAGER = manager.AstroidManager()
4142

4243

4344
# .infer method ###############################################################
4445

45-
46+
@cython.binding(True)
4647
def infer_end(self, context=None):
4748
"""inference's end for node such as Module, ClassDef, FunctionDef,
4849
Const...
@@ -78,6 +79,7 @@ def _infer_sequence_helper(node, context=None):
7879

7980
@decorators.raise_if_nothing_inferred
8081
@decorators.path_wrapper
82+
@cython.binding(True)
8183
def infer_sequence(self, context=None):
8284
if not any(isinstance(e, nodes.Starred) for e in self.elts):
8385
yield self
@@ -93,6 +95,7 @@ def infer_sequence(self, context=None):
9395
nodes.Set._infer = infer_sequence
9496

9597

98+
@cython.binding(True)
9699
def infer_map(self, context=None):
97100
if not any(isinstance(k, nodes.DictUnpack) for k, _ in self.items):
98101
yield self
@@ -171,6 +174,7 @@ def _higher_function_scope(node):
171174
return current.parent
172175
return None
173176

177+
@cython.binding(True)
174178
def infer_name(self, context=None):
175179
"""infer a Name: use name lookup rules"""
176180
frame, stmts = self.lookup(self.name)
@@ -190,14 +194,13 @@ def infer_name(self, context=None):
190194
return bases._infer_stmts(stmts, context, frame)
191195

192196
# 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))
196198
nodes.AssignName.infer_lhs = infer_name # won't work with a path wrapper
197199

198200

199201
@decorators.raise_if_nothing_inferred
200202
@decorators.path_wrapper
203+
@cython.binding(True)
201204
def infer_call(self, context=None):
202205
"""infer a Call node by trying to guess what the function returns"""
203206
callcontext = context.clone()
@@ -226,6 +229,7 @@ def infer_call(self, context=None):
226229

227230
@decorators.raise_if_nothing_inferred
228231
@decorators.path_wrapper
232+
@cython.binding(True)
229233
def infer_import(self, context=None, asname=True):
230234
"""infer an Import node: return the imported module/object"""
231235
name = context.lookupname
@@ -247,6 +251,7 @@ def infer_import(self, context=None, asname=True):
247251
nodes.Import._infer = infer_import
248252

249253

254+
@cython.binding(True)
250255
def infer_name_module(self, name):
251256
context = contextmod.InferenceContext()
252257
context.lookupname = name
@@ -256,6 +261,7 @@ def infer_name_module(self, name):
256261

257262
@decorators.raise_if_nothing_inferred
258263
@decorators.path_wrapper
264+
@cython.binding(True)
259265
def infer_import_from(self, context=None, asname=True):
260266
"""infer a ImportFrom node: return the imported module/object"""
261267
name = context.lookupname
@@ -288,6 +294,7 @@ def infer_import_from(self, context=None, asname=True):
288294

289295

290296
@decorators.raise_if_nothing_inferred
297+
@cython.binding(True)
291298
def infer_attribute(self, context=None):
292299
"""infer an Attribute node by using getattr on the associated object"""
293300
for owner in self.expr.infer(context):
@@ -325,6 +332,7 @@ def infer_attribute(self, context=None):
325332

326333
@decorators.raise_if_nothing_inferred
327334
@decorators.path_wrapper
335+
@cython.binding(True)
328336
def infer_global(self, context=None):
329337
if context.lookupname is None:
330338
raise exceptions.InferenceError(node=self, context=context)
@@ -345,6 +353,7 @@ def infer_global(self, context=None):
345353

346354

347355
@decorators.raise_if_nothing_inferred
356+
@cython.binding(True)
348357
def infer_subscript(self, context=None):
349358
"""Inference for subscripts
350359
@@ -407,6 +416,7 @@ def infer_subscript(self, context=None):
407416

408417
@decorators.raise_if_nothing_inferred
409418
@decorators.path_wrapper
419+
@cython.binding(True)
410420
def _infer_boolop(self, context=None):
411421
"""Infer a boolean operation (and / or / not).
412422
@@ -462,6 +472,7 @@ def _infer_boolop(self, context=None):
462472

463473
# UnaryOp, BinOp and AugAssign inferences
464474

475+
@cython.binding(True)
465476
def _filter_operation_errors(self, infer_callable, context, error):
466477
for result in infer_callable(self, context):
467478
if isinstance(result, error):
@@ -473,6 +484,7 @@ def _filter_operation_errors(self, infer_callable, context, error):
473484
yield result
474485

475486

487+
@cython.binding(True)
476488
def _infer_unaryop(self, context=None):
477489
"""Infer what an UnaryOp should return when evaluated."""
478490
for operand in self.operand.infer(context):
@@ -529,6 +541,7 @@ def _infer_unaryop(self, context=None):
529541

530542
@decorators.raise_if_nothing_inferred
531543
@decorators.path_wrapper
544+
@cython.binding(True)
532545
def infer_unaryop(self, context=None):
533546
"""Infer what an UnaryOp should return when evaluated."""
534547
yield from _filter_operation_errors(self, _infer_unaryop, context,
@@ -711,6 +724,7 @@ def _infer_binary_operation(left, right, binary_opnode, context, flow_factory):
711724
yield util.BadBinaryOperationMessage(left_type, binary_opnode.op, right_type)
712725

713726

727+
@cython.binding(True)
714728
def _infer_binop(self, context):
715729
"""Binary operation inference logic."""
716730
if context is None:
@@ -745,6 +759,7 @@ def _infer_binop(self, context):
745759

746760
@decorators.yes_if_nothing_inferred
747761
@decorators.path_wrapper
762+
@cython.binding(True)
748763
def infer_binop(self, context=None):
749764
return _filter_operation_errors(self, _infer_binop, context,
750765
util.BadBinaryOperationMessage)
@@ -753,6 +768,7 @@ def infer_binop(self, context=None):
753768
nodes.BinOp._infer = infer_binop
754769

755770

771+
@cython.binding(True)
756772
def _infer_augassign(self, context=None):
757773
"""Inference logic for augmented binary operations."""
758774
if context is None:
@@ -779,6 +795,7 @@ def _infer_augassign(self, context=None):
779795

780796
@decorators.raise_if_nothing_inferred
781797
@decorators.path_wrapper
798+
@cython.binding(True)
782799
def infer_augassign(self, context=None):
783800
return _filter_operation_errors(self, _infer_augassign, context,
784801
util.BadBinaryOperationMessage)
@@ -791,6 +808,7 @@ def infer_augassign(self, context=None):
791808

792809
@decorators.raise_if_nothing_inferred
793810
@decorators.path_wrapper
811+
@cython.binding(True)
794812
def infer_arguments(self, context=None):
795813
name = context.lookupname
796814
if name is None:
@@ -801,6 +819,7 @@ def infer_arguments(self, context=None):
801819

802820
@decorators.raise_if_nothing_inferred
803821
@decorators.path_wrapper
822+
@cython.binding(True)
804823
def infer_assign(self, context=None):
805824
"""infer a AssignName/AssignAttr: need to inspect the RHS part of the
806825
assign node
@@ -819,6 +838,7 @@ def infer_assign(self, context=None):
819838

820839
@decorators.raise_if_nothing_inferred
821840
@decorators.path_wrapper
841+
@cython.binding(True)
822842
def infer_empty_node(self, context=None):
823843
if not self.has_underlying_object():
824844
yield util.Uninferable
@@ -832,12 +852,14 @@ def infer_empty_node(self, context=None):
832852

833853
@decorators.raise_if_nothing_inferred
834854
@decorators.path_wrapper
855+
@cython.binding(True)
835856
def infer_index(self, context=None):
836857
return self.value.infer(context)
837858
nodes.Index._infer = infer_index
838859

839860
# TODO: move directly into bases.Instance when the dependency hell
840861
# will be solved.
862+
@cython.binding(True)
841863
def instance_getitem(self, index, context=None):
842864
# Rewrap index to Const for this case
843865
new_context = contextmod.bind_context_to_node(context, self)

astroid/protocols.py renamed to astroid/protocols.pyx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import collections
2424
import operator as operator_mod
2525
import sys
26+
cimport cython
2627

2728
from astroid import Store
2829
from astroid import arguments
@@ -118,6 +119,7 @@ def _infer_unary_op(obj, op):
118119

119120

120121
@decorators.yes_if_nothing_inferred
122+
@cython.binding(True)
121123
def const_infer_binary_op(self, opnode, operator, other, context, _):
122124
not_implemented = nodes.Const(NotImplemented)
123125
if isinstance(other, nodes.Const):
@@ -141,6 +143,7 @@ def const_infer_binary_op(self, opnode, operator, other, context, _):
141143
nodes.Const.infer_binary_op = const_infer_binary_op
142144

143145

146+
@cython.binding(True)
144147
def _multiply_seq_by_int(self, opnode, other, context):
145148
node = self.__class__(parent=opnode)
146149
elts = []
@@ -167,6 +170,7 @@ def _filter_uninferable_nodes(elts, context):
167170

168171

169172
@decorators.yes_if_nothing_inferred
173+
@cython.binding(True)
170174
def tl_infer_binary_op(self, opnode, operator, other, context, method):
171175
not_implemented = nodes.Const(NotImplemented)
172176
if isinstance(other, self.__class__) and operator == '+':
@@ -195,6 +199,7 @@ def tl_infer_binary_op(self, opnode, operator, other, context, method):
195199

196200

197201
@decorators.yes_if_nothing_inferred
202+
@cython.binding(True)
198203
def instance_class_infer_binary_op(self, opnode, operator, other, context, method):
199204
return method.infer_call_result(self, context)
200205

@@ -252,6 +257,7 @@ def _resolve_looppart(parts, asspath, context):
252257
break
253258

254259
@decorators.raise_if_nothing_inferred
260+
@cython.binding(True)
255261
def for_assigned_stmts(self, node=None, context=None, asspath=None):
256262
if isinstance(self, nodes.AsyncFor) or getattr(self, 'is_async', False):
257263
# Skip inferring of async code for now
@@ -270,6 +276,7 @@ def for_assigned_stmts(self, node=None, context=None, asspath=None):
270276
nodes.Comprehension.assigned_stmts = for_assigned_stmts
271277

272278

279+
@cython.binding(True)
273280
def sequence_assigned_stmts(self, node=None, context=None, asspath=None):
274281
if asspath is None:
275282
asspath = []
@@ -286,12 +293,14 @@ def sequence_assigned_stmts(self, node=None, context=None, asspath=None):
286293
nodes.Tuple.assigned_stmts = sequence_assigned_stmts
287294
nodes.List.assigned_stmts = sequence_assigned_stmts
288295

296+
@cython.binding(True)
289297
def assend_assigned_stmts(self, node=None, context=None, asspath=None):
290298
return self.parent.assigned_stmts(node=self, context=context)
291299
nodes.AssignName.assigned_stmts = assend_assigned_stmts
292300
nodes.AssignAttr.assigned_stmts = assend_assigned_stmts
293301

294302

303+
@cython.binding(True)
295304
def _arguments_infer_argname(self, name, context):
296305
# arguments information may be missing, in which case we can't do anything
297306
# more
@@ -339,6 +348,7 @@ def _arguments_infer_argname(self, name, context):
339348
yield util.Uninferable
340349

341350

351+
@cython.binding(True)
342352
def arguments_assigned_stmts(self, node=None, context=None, asspath=None):
343353
if context.callcontext:
344354
# reset call context/name
@@ -353,6 +363,7 @@ def arguments_assigned_stmts(self, node=None, context=None, asspath=None):
353363

354364

355365
@decorators.raise_if_nothing_inferred
366+
@cython.binding(True)
356367
def assign_assigned_stmts(self, node=None, context=None, asspath=None):
357368
if not asspath:
358369
yield self.value
@@ -363,6 +374,7 @@ def assign_assigned_stmts(self, node=None, context=None, asspath=None):
363374
assign_path=asspath, context=context)
364375

365376

377+
@cython.binding(True)
366378
def assign_annassigned_stmts(self, node=None, context=None, asspath=None):
367379
for inferred in assign_assigned_stmts(self, node, context, asspath):
368380
if inferred is None:
@@ -416,6 +428,7 @@ def _resolve_asspart(parts, asspath, context):
416428

417429

418430
@decorators.raise_if_nothing_inferred
431+
@cython.binding(True)
419432
def excepthandler_assigned_stmts(self, node=None, context=None, asspath=None):
420433
for assigned in node_classes.unpack_infer(self.type):
421434
if isinstance(assigned, nodes.ClassDef):
@@ -429,6 +442,7 @@ def excepthandler_assigned_stmts(self, node=None, context=None, asspath=None):
429442
nodes.ExceptHandler.assigned_stmts = excepthandler_assigned_stmts
430443

431444

445+
@cython.binding(True)
432446
def _infer_context_manager(self, mgr, context):
433447
try:
434448
inferred = next(mgr.infer(context=context))
@@ -480,6 +494,7 @@ def _infer_context_manager(self, mgr, context):
480494

481495

482496
@decorators.raise_if_nothing_inferred
497+
@cython.binding(True)
483498
def with_assigned_stmts(self, node=None, context=None, asspath=None):
484499
"""Infer names and other nodes from a *with* statement.
485500
@@ -542,6 +557,7 @@ def __enter__(self):
542557

543558

544559
@decorators.yes_if_nothing_inferred
560+
@cython.binding(True)
545561
def starred_assigned_stmts(self, node=None, context=None, asspath=None):
546562
"""
547563
Arguments:

astroid/raw_building.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import logging
2323
import os
2424
import sys
2525
import types
26+
cimport cython
2627

2728
from astroid import bases
2829
from astroid import manager
@@ -73,7 +74,6 @@ def attach_dummy_node(node, name, runtime_object=_marker):
7374
enode.object = runtime_object
7475
_attach_local_node(node, enode, name)
7576

76-
cimport cython
7777
@cython.binding(True)
7878
def _has_underlying_object(self):
7979
return self.object is not None and self.object is not _marker

0 commit comments

Comments
 (0)