Opened 6 years ago

Last modified 6 years ago

#288 new enhancement

method aliasing via assignment

Reported by: rmurri Owned by: somebody
Priority: minor Milestone: wishlist
Component: Code Generation Keywords:
Cc:

Description (last modified by scoder)

It would be nice to have method aliasing via assignment, i.e.

def foo():
  # do something
bar = foo

As of Cython 0.11.1, this works with "def" and "cpdef" methods, but
fails for "cdef" ones::

def foo():
    print "foo"
bar = foo

cdef foo2():
     print "foo2"
bar2 = foo2  # fails with error::  Cannot convert 'object (void)' to Python object


cdef class A(object):
     def foo(self):
         print "A.foo"
     bar = foo

     cdef foo2(self):
         print "A.foo2"
     bar2 = foo2  # fails with error:: Cannot convert 'object (A)' to Python object

     cpdef foo3(self):
         print "A.foo3"
     bar3 = foo3

bar()
bar2()
a = A()
a.foo()
a.foo2()
a.foo3()

It also fails for some instances of Python's "__special__" methods, see
e.g. http://codespeak.net/pipermail/cython-dev/2009-April/004898.html

Change History (1)

comment:1 Changed 6 years ago by scoder

  • Description modified (diff)

Note that the assignments to cdef class attributes fail because you haven't declared the target name to have the same type as the function (which does not have a Python object type). So this part of the feature depends on type inference and assignment tracking (i.e. flow analysis).

Note: See TracTickets for help on using tickets.