是否可以装饰方法参数?例如:
class SampleEntity (BaseEntity) :
def someOperation (self, @Param(type="int", unit="MB")i, str) :
pass
基本上,我希望开发人员能够指定类、属性、方法、参数等元数据,以便我稍后进行处理。对于类和方法,我可以使用装饰器。所以我想知道如何处理方法参数。
谢谢, Litty
def func(arg: Param(type = 'int', unit = 'MB')):
pass
注解可以包含任何你想要的信息,语言并不定义应该放什么。你可以稍后使用 func.__annotations__
字典访问它们。
func_annotations
,而不是 __annotations__
。这是否已经过时了?PEP是否会过时?:). 我一直在收到AttributeError,无法理解我做错了什么。 - thule__annotations__
中,所以我猜他们决定在发布PEP和实现之间的某个时候进行更改。 - Cat Plus Plus不行。你可以装饰函数和类,但不能装饰参数。