Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inspect
- import asyncio
- class AsyncClassWrapper:
- def __init__(self, wrapped):
- self.wrapped = wrapped
- def __getattr__(self, item):
- w = getattr(self.wrapped, item)
- async def wrapper(*args,**kwargs):
- val = w(self.wrapped, *args, **kwargs)
- return await val if inspect.isawaitable(val) else val
- if inspect.isfunction(w):
- return wrapper
- elif isinstance(w,property):
- return w.fget(self.wrapped)
- else:
- return w
- class session:
- test1='test1'
- async def test2(self,arg):
- print(arg)
- async def test3(self,arg):
- print("test3")
- @property
- def test4(self):
- return "test4"
- async def t():
- s = AsyncClassWrapper(session)
- print(s.test1)
- await s.test2("test2")
- await s.test3("k")
- print(s.test4)
- s.test5 = "test5"
- print(s.test5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement