yr.method

Contents

yr.method#

yr.method(*args, **kwargs)[source]#

Used to decorate class member methods.

Parameters:

return_nums (int) – The number of return values of the member function, restrictions: greater than 0, this parameter is not recommended to be set too large.

Returns:

The decorated function. Data type is FunctionType.

Raises:
  • ValueError – If the input parameters are incorrect.

  • TypeError – If the type of the input parameters is incorrect.

Example

>>> import yr
>>> yr.init()
>>>
>>> @yr.instance
... class Instance:
...     sum = 0
...
...     def add(self, a):
...         self.sum += a
...
...     def get(self):
...         return self.sum
...
...     @yr.method(return_nums=2)
...     def detail(self, a, b):
...         return a, b
...
>>> ins = Instance.invoke()
>>> res1, res2 = ins.detail.invoke(0, 1)
>>> print("detail result1:", yr.get(res1))
detail result1: 0
>>> print("detail result2:", yr.get(res2))
detail result2: 1
>>> ins.terminate()
>>>
>>> yr.finalize()