-
Notifications
You must be signed in to change notification settings - Fork 1
/
oproperty.py
51 lines (49 loc) · 1.82 KB
/
oproperty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def init():
import builtins as B
from ctypes import py_object
def check(o):
if B.isinstance(o, B.property):
return B.getattr(o, "__outsideproperty__", None) or B.getattr(o.fget, "__outsideproperty__", None)
return False
class balsglo(dict):
__slots__ = ()
def __getitem__(self, x):
return obj.fget() if check(obj := B.dict.__getitem__(self, x)) else obj
def __setitem__(self, x, y):
obj = self.get(x)
if check(obj := self.get(x)):
if obj.fset:
return obj.fset(y)
raise ValueError(f"outside property {x!r} has no setter")
return B.dict.__setitem__(self, x, y)
def __delitem__(self, x):
if check(obj := self.get(x)):
if obj.fdel:
return obj.fdel()
raise ValueError(f"outside property {x!r} has no deleter")
return B.dict.__delitem__(self, x)
py_object.from_address(id(globals()) + tuple.__itemsize__).value = balsglo
def oproperty(fget=None, fset=None, fdel=None, doc=None):
import builtins as B
def wrap(f):
f.__outsideproperty__ = True
f = B.property(f, fset, fdel, doc)
return f
if fget is not None:
return wrap(fget)
return wrap
class olazyproperty(property):
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
import builtins as B
B.property.__init__(self, fget, fset, fdel, doc)
def setter(self, f, /):
import builtins as B
B.property.setter(self, f)
def getter(self, f, /):
import builtins as B
B.property.getter(self, f)
def deleter(self, f, /):
import builtins as B
B.property.deleter(self, f)
def init(self, /):
self.__outsideproperty__ = True