获取在类“属性方法”上设置的属性

I have this simple decorator which sets an attribute mark='marked' on the decorated method

def mark(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        return fn(*args, **kwargs)
    setattr(wrapper, 'mark', 'marked')
    return wrapper

我在这样的类属性方法上使用它

class Car(object):

    @property
    @mark
    def move(self):
        return "move"

Now since Car.move is a property method, how do I access the marked attribute I created?

>>> c = Car()
>>> getattr(c.move, 'mark')
AttributeError: 'str' object has no attribute 'mark'

The error makes sense since c.move invokes the __get__ method on the property descriptor which returns a string.

有其他方法可以做到这一点吗?

评论