Lit*_*tty 3 python methods arguments decorator
是否可以修饰方法参数?就像是:
class SampleEntity (BaseEntity) :
def someOperation (self, @Param(type="int", unit="MB")i, str) :
pass
Run Code Online (Sandbox Code Playgroud)
基本上我希望开发人员能够指定有关类,属性,方法,参数等的元数据,稍后我们可以处理这些元数据.对于类和方法,我可以使用装饰器.所以我想知道如何为方法参数做这件事.
谢谢,Litty
不,但在Python 3中,您可以使用注释.
def func(arg: Param(type = 'int', unit = 'MB')):
pass
Run Code Online (Sandbox Code Playgroud)
注释可以包含您想要的任何信息,语言不能定义应该去哪里.您可以func.__annotations__稍后使用dict 访问它们.