deepfos.lib.decorator.flagmethod

deepfos.lib.decorator.flagmethod(flag)

进出方法时设置flag

用于method的装饰器,当调用被装饰的方法时,会将 self.flag 置为 True,结束调用时(包括异常退出),置为 False

参数

flag (str) – 作为标识的属性名

>>> class Example:
...     def __init__(self):
...         self.flag = False
...
...     @flagmethod('flag')
...     def foo(self, arg):
...         self.bar()
...         pass
...
...     @flagmethod('flag')
...     async def async_foo(self, arg):
...         self.bar()
...         pass
...
...     def bar(self):
...         print(self.flag)
...
>>> example = Example()
>>> example.foo(1)
True
>>> import asyncio
>>> asyncio.run(example.async_foo(1))
True
>>> example.flag
False
返回类型

Callable[[~F], ~F]