Commit 191b9231 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix infinite recurison when using super with cpdef methods.

This should also be a (small) performance improvement.
parent a7b4b0f0
......@@ -84,6 +84,8 @@ Bugs fixed
* Correctly handle ``from cython.submodule cimport name``.
* Fix infinite recursion when using super with cpdef methods.
Other changes
-------------
......
......@@ -2286,6 +2286,7 @@ class CFuncDefNode(FuncDefNode):
"private types")
def call_self_node(self, omit_optional_args=0, is_module_scope=0):
# OLD - DELETE
from . import ExprNodes
args = self.type.args
if omit_optional_args:
......@@ -2300,6 +2301,18 @@ class CFuncDefNode(FuncDefNode):
c_call = ExprNodes.SimpleCallNode(self.pos, function=cfunc, args=[ExprNodes.NameNode(self.pos, name=n) for n in arg_names[1-is_module_scope:]], wrapper_call=skip_dispatch)
return ReturnStatNode(pos=self.pos, return_type=PyrexTypes.py_object_type, value=c_call)
def call_self_node(self, omit_optional_args=0, is_module_scope=0):
from . import ExprNodes
args = self.type.args
if omit_optional_args:
args = args[:len(args) - self.type.optional_arg_count]
arg_names = [arg.name for arg in args]
cfunc = ExprNodes.PythonCapiFunctionNode(self.pos, self.entry.name, self.entry.func_cname, self.type)
cfunc.entry = self.entry
skip_dispatch = not is_module_scope or Options.lookup_module_cpdef
c_call = ExprNodes.SimpleCallNode(self.pos, function=cfunc, args=[ExprNodes.NameNode(self.pos, name=n) for n in arg_names], wrapper_call=skip_dispatch)
return ReturnStatNode(pos=self.pos, return_type=PyrexTypes.py_object_type, value=c_call)
def declare_arguments(self, env):
for arg in self.type.args:
if not arg.name:
......
......@@ -63,13 +63,29 @@ def test_class_cell_empty():
cdef class CClassBase(object):
def method(self):
return 1
return 'def'
# cpdef method_cp(self):
# return 'cpdef'
# cdef method_c(self):
# return 'cdef'
# def call_method_c(self):
# return self.method_c()
cdef class CClassSuper(CClassBase):
cdef class CClassSub(CClassBase):
"""
>>> CClassSuper().method()
1
>>> CClassSub().method()
'def'
"""
# >>> CClassSub().method_cp()
# 'cpdef'
# >>> CClassSub().call_method_c()
# 'cdef'
def method(self):
return super().method()
# cpdef method_cp(self):
# return super().method_cp()
# cdef method_c(self):
# return super().method_c()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment