python - Is it pythonic to write decorators that doesn't return a callable? -


i observed python decorator need not return callable. tried below example in django queryset. how bad practice?

class myqueryset(models.queryset):      ...      def each(self, save=false, func=none):         if hasattr(save, '__call__'):             func = save             save = false         obj in self:             func(obj)             if save:                 obj.save()  mymodel.objects.each(lambda x: x.delete())  # delete mymodels database  @person.objects.each(save=true): def make_older(person):     ''' increase age of people '''     person.age += 1 

ps:

are there situations technique can used more useful purpose?

from python glossary:

decorator

a function returning function, applied function transformation using @wrapper syntax. common examples decorators classmethod() , staticmethod().

edit: decorator not return callable not fall under official defnition of term 'decorator'. unpythonic.


Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -