class-decorator

Python subclass method to inherit decorator from superclass method

你说的曾经没有我的故事 提交于 2020-02-03 19:52:39
问题 I have a superclass that has a retrieve() method, and its subclasses each implement their own retrieve() method. I'd like every retrieve() method to be decorated to cache the return value when it receive the same args, without having to decorate the method in every subclass. Decorators don't seem to be inherited. I could probably call the superclass's method which would in turn set the cache, but currently my superclass raises a NotImplemented exception, which I like. import json import

Python subclass method to inherit decorator from superclass method

江枫思渺然 提交于 2020-02-03 19:50:03
问题 I have a superclass that has a retrieve() method, and its subclasses each implement their own retrieve() method. I'd like every retrieve() method to be decorated to cache the return value when it receive the same args, without having to decorate the method in every subclass. Decorators don't seem to be inherited. I could probably call the superclass's method which would in turn set the cache, but currently my superclass raises a NotImplemented exception, which I like. import json import

Python subclass method to inherit decorator from superclass method

旧时模样 提交于 2020-02-03 19:49:57
问题 I have a superclass that has a retrieve() method, and its subclasses each implement their own retrieve() method. I'd like every retrieve() method to be decorated to cache the return value when it receive the same args, without having to decorate the method in every subclass. Decorators don't seem to be inherited. I could probably call the superclass's method which would in turn set the cache, but currently my superclass raises a NotImplemented exception, which I like. import json import

Passing 'self' parameter during methods decorating in Python [duplicate]

和自甴很熟 提交于 2019-12-31 02:19:13
问题 This question already has answers here : Decorating Python class methods - how do I pass the instance to the decorator? (4 answers) Python decorator, self is mixed up [duplicate] (3 answers) Closed 4 months ago . I want to create decorator that shows which parameters were passed to function and methods. I have already written the code for functions, but methods are giving me a headaches. This is function decorator that works as intended: from functools import update_wrapper class