Ticket #742 (closed defect: fixed)

Opened 20 months ago

Last modified 20 months ago

using 'self' in the closure of extension type methods is broken

Reported by: scoder Owned by: scoder
Priority: critical Milestone: 0.16
Component: Code Generation Keywords:
Cc:

Description

The following fails at runtime:

@cython.cclass
class ExtType(object):
    def const1(self):
        return 1

    def ext_method(self, a=2):
        """
        >>> x = ExtType()
        >>> x.ext_method()()
        (1, 2)
        >>> x.ext_method(3)()
        (1, 3)
        """
        def func():
            return self.const1(), a
        return func

The error message is:

NameError: free variable 'self' referenced before assignment in enclosing scope

The problem is that the 'self' field is not being set in the closure instance. The same issue leads to crashes for generator methods.

Change History

Changed 20 months ago by scoder

  • owner changed from somebody to scoder
  • status changed from new to assigned

Changed 20 months ago by scoder

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone changed from wishlist to 0.16
Note: See TracTickets for help on using tickets.