是否可以修饰方法参数?像这样的东西:
class SampleEntity (BaseEntity) :
def someOperation (self, @Param(type="int", unit="MB")i, str) :
pass
基本上,我希望开发人员能够指定有关类、属性、方法、参数等的元数据,我稍后可以处理这些元数据。对于类和方法,我可以使用装饰器。所以我想知道如何为方法参数执行此操作。
谢谢, 小
最佳答案
不,但是在 Python 3 中你可以使用 annotations .
def func(arg: Param(type = 'int', unit = 'MB')):
pass
注释可以包含您想要的任何信息,语言并没有定义应该放在那里的内容。您可以稍后使用 func.__annotations__
dict 访问它们。
关于 python : is decorators for method arguments possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6122496/