from typing import Any class Origin: o: str = 'o1' def o1(self): return self.o def o2(self): return 'o2' class Proxy: self_attrs: list = None origin_obj = None def __init__(self, o) -> None: self.self_attrs = list(Proxy.__dict__) self.origin_obj = o def o1(self): return 'Proxy ->' + self.origin_obj.o1() def __getattribute__(self, name: str) -> Any: if name in Proxy.__dict__.keys(): return super().__getattribute__(name) return self.origin_obj.__getattribute__(name) t = Proxy(Origin()) print(t.o1()) print(t.o2())
输出: