Special Method Protocols

__delete__() — attributes protocol

Implement descriptor deletion, invoked for del obj.attr. A descriptor defining __delete__ is a data descriptor. Choose what deletion means for the managed storage.

Formal Syntax & Structure

python syntaxpython
def __delete__(self, instance):

Parameters & Attributes

NameTypeDescription
instanceobjectReceiving instance.

Return Value

None

Deletion has no meaningful result.

Working Example

Example Snippetpython
class Field:    def __get__(self, instance, owner=None):        if instance is None: return self        return instance._value    def __delete__(self, instance): del instance._valueclass Record:    value=Field()def demo():    r=Record(); r._value=7; del r.value    return hasattr(r,"_value")print(demo())
Python Reference