[pypy-issue] Issue #2629: SIGSEGV when mistyping __del__ for __delete__ in a property (pypy/pypy)

Artur Siekielski issues-reply at bitbucket.org
Sun Aug 13 07:34:25 EDT 2017


New issue 2629: SIGSEGV when mistyping __del__ for __delete__ in a property
https://bitbucket.org/pypy/pypy/issues/2629/sigsegv-when-mistyping-__del__-for

Artur Siekielski:

The following code results in SIGSEGV (PyPy 5.8.0, Linux). Note that a property should define __delete__, not __del__. CPython gives a proper message.


```
#!python

undefined = object()

class cached_property(property):

    def __init__(self, func):
        self.__name__ = func.__name__
        self.__module__ = func.__module__
        self.__doc__ = func.__doc__
        self.func = func

    def __set__(self, obj, value):
        obj.__dict__[self.__name__] = value

    def __get__(self, obj, type=None):
        if obj is None:
            return self
        value = obj.__dict__.get(self.__name__, undefined)
        if value is undefined:
            value = self.func(obj)
            obj.__dict__[self.__name__] = value
        return value

    def __del__(self, obj):
        print '__del__'


class A(object):
    @cached_property
    def f(self):
        return 1

a = A()
del a.f

```




More information about the pypy-issue mailing list