Python: are decorators possible for method arguments?

Is it possible to decorate the arguments of a method? Sort of:

class SampleEntity (BaseEntity) :
    def someOperation (self, @Param(type="int", unit="MB")i, str) :
        pass

Basically, I want the developer to be able to specify metadata about the class, properties, methods, arguments, etc., which I can process later. For class and methods, I could use decorators. Therefore, I was wondering how to do this for method arguments.

Thanks, LITTY

+3
source share
5 answers

No, but in Python 3 you can use annotations .

def func(arg: Param(type = 'int', unit = 'MB')):
   pass

Annotations can contain any information you want, the language does not determine what should go there. You can access them using func.__annotations__dict later.

+8
source

, docstring, .

, , enthought.

, .

+4

. , .

+3

, .

, .

+1

. , , , .

:

def dostuff(f: str, x: "Hula hula!"):
     pass
+1

All Articles