Page MenuHomeVyOS Platform

op-mode scripts with type hints in `return` do not work
Closed, ResolvedPublicBUG

Description

If we define the return type in a function:

def do_something(input_data: str) -> str:

this will break its execution using the new opmode.py.

The problem is in typing.get_type_hints() function - it will return return as one of type hints:

>> typing.get_type_hints(do_something)
{'input_data': <class 'str'>, 'return': <class 'str'>}

What will be wrongly interpreted by opmode.py as a required argument for operation: https://github.com/vyos/vyos-1x/blob/b01f27b3bb3f4cbc6096011856d83009d0440313/python/vyos/opmode.py#L107-L117

We need to add an exception to the return hint to skip it.

Details

Difficulty level
Easy (less than an hour)
Version
1.4-rolling-202208291850
Why the issue appeared?
Implementation mistake
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

Viacheslav changed the task status from In progress to Needs testing.Sep 27 2022, 12:05 PM
dmbaturin changed Why the issue appeared? from Will be filled on close to Implementation mistake.