Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does deconstructible do in Python?

What does deconstructible decorator in Python do? I encountered this decorator looking at someone else code, but I have searched the Python docs and cannot find what this decorator actually does?

@deconstructible
class UserValidator(object):
    def __call__(self, value):
        if value:
           etc

Given the code above, what does adding 'deconstructible' do to this class?

like image 442
MarkK Avatar asked Dec 19 '16 11:12

MarkK


2 Answers

By using Google I managed to find that it is part of Django:

https://docs.djangoproject.com/en/stable/topics/migrations/#adding-a-deconstruct-method

As long as all of the arguments to your class’ constructor are themselves serializable, you can use the @deconstructible class decorator from django.utils.deconstruct to add the deconstruct() method

like image 92
DeepSpace Avatar answered Nov 16 '22 02:11

DeepSpace


def deconstructible(*args, **kwargs):
    """
    Class decorator that allow the decorated class to be serialized
    by the migrations subsystem.

    Accepts an optional kwarg `path` to specify the import path.
    """
like image 33
davidj411 Avatar answered Nov 16 '22 02:11

davidj411