blob: 69c1e65e2eea0425c8ffd392e1471aa0bfb71477 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class reify(object):
""" Put the result of a method which uses this (non-data)
descriptor decorator in the instance dict after the first call,
effectively replacing the decorator with an instance variable."""
def __init__(self, wrapped):
self.wrapped = wrapped
def __get__(self, inst, objtype=None):
if inst is None:
return self
val = self.wrapped(inst)
setattr(inst, self.wrapped.__name__, val)
return val
|