You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New RETURN statement for returning from user keywords #4078
We currently have two ways to return from a user keyword:
[Return] setting that defines what to return once the keyword has been executed.
Return From Keyword keyword and its variants Return From Keyword If, Run Keyword And Return, Run Keyword And Return If.
This is problematic for various reasons:
[Return] is more widely used but it has pretty bad limitations. Most importantly, it cannot be used conditionally with IF/ELSE structures.
Using keywords solves the above problem but using keywords for something like this is awkward.
It's not good to have multiple ways to solve the same problem.
My proposal is that we add separate RETURN statement that can be used to return from a user keyword. The statement itself should return unconditionally, but it would be usable in IF/ELSE. Example usages:
*** Keywords ***Return at the end
Some Keyword
${result} = Another Keyword
RETURN ${result}Return conditionally
IF ${condition}
RETURN Something
ELSE
RETURN Something else
END
Early return
IF ${not applicable}
RETURN
END
Some Keyword
Another Keyword
Reacted by Teppo Koskinen, MininAS, Mateusz Nojek and Kyriakos (Dominick) Sidiropoulos
If we add RETURN, then we should deprecate and remove the [Return] setting. Probably should wait at least until RF 5.1 before we emit an actual deprecation warning, but documentation should be updated to mention that RETURN is the way forward. External tools like RoboCop could warn about the deprecated usage even earlier and RoboTidy could possibly convert from [Return] to RETURN. Robot itself could probably make it an error to use both RETURN and [Return] in one keyword.
I'm not sure what to do with Return From Keyword and its variants. I consider it more important to remove syntax that's not anymore needed than to remove keywords. In addition to that, conditional variables like Return From Keyword If make it possible to create shorter data than IF and RETURN combination. That said, it would probably be better to deprecate also all these to have only one way to return in the end. BuiltIn having less keywords wouldn't hurt either.
A common use case when returning is to execute a lower level keyword and returning its return value. Because we cannot separate
RETURN value # Return this value
from
RETURN Keyword # Run this keyword and return its result
I think its better to just support returning values. If you need to run a keyword and return its return value, it needs to be done separately:
${result} = Keyword # Run this keyword
RETURN ${result} # and return its result
The underlying issue here is that same that it would sometimes be nice to pass keyword return values directly as argument, but we cannot really separate
Keyword argument # Pass this argument to the keyword
from
Keyword Another Keyword # Run this keyword and pass its return value as argument
either. We already have #3187 about adding some inline keyword call syntax and it should naturally work with RETURN as well.
This enhancement requires changes on many places starting from the parser and continuing to the execution side. I explain here briefly what's needed on the parsing side and can write separate comment later about changes on the execution side. This information hopefully helps someone interested to contribute and same instructions apply also to BREAK and CONTINUE (#4079).
New lexer in statementlexers.py. Logic very much the same as in e.g. EndLexer.
New lexer needs to be used by appropriate higher level lexers in blocklexers.py. In practice relevant block lexers need to return the new statement lexer from their lexer_classes method.
New parsing model object in statements.py. End statement can be used as an example.
These changes needed to be tested using unit testes in utest/parsing. It would be good to add some tests for the lexer in test_lexer.py, but that file is so huge it's hard to see where these new tests would fi. The whole flow can be tested with tests in test_model.py and from_params method should be tested in test_statements.py.
Agreed, [Return] and all Return ... keywords should be deprecated. In RF 5.0 that deprecation will only be a note in the docs, though, because it would be annoying to get deprecation warnings in RF 5.0 from syntax that you must use with earlier. We can then consider deprecating these loudly in RF 5.1 or later. There's no big hurry in removing them either. It would be annoying to migrate from RF 4.1 to e.g. RF 5.2 if e.g. [Return] wouldn't work at all in the latter.
I expect that RoboTidy and RoboCop can help in transition.
changed the title [-]New `RETURN` statement for returning from a user keyword[/-][+]New `RETURN` statement for returning from user keywords[/+]on Nov 18, 2021
I am ok with adding RETURN, but I do not think removing [Return] should be considered. It is going to force rewrite thousands of already created resources.
I am ok with adding RETURN, but I do not think removing [Return] should be considered. It is going to force rewrite thousands of already created resources.
I already have written transformer in robotidy autoformatting tool that handles it for you (it will be released before 5.0 together with other changes for 5.0). So it should'nt be the issue
In the latest release 2.1.b1, RIDE continues to use the fixed parameter Return Value under Settings. This corresponds to the value [Return] in the text editor. Robot Framework 7.1 shows then the error messages:
The '[Return]' setting is deprecated. Use the 'RETURN' statement instead.
Is there any adjustment to this?
Activity
pekkaklarck commentedon Sep 6, 2021
If we add
RETURN, then we should deprecate and remove the[Return]setting. Probably should wait at least until RF 5.1 before we emit an actual deprecation warning, but documentation should be updated to mention thatRETURNis the way forward. External tools like RoboCop could warn about the deprecated usage even earlier and RoboTidy could possibly convert from[Return]toRETURN. Robot itself could probably make it an error to use bothRETURNand[Return]in one keyword.I'm not sure what to do with
Return From Keywordand its variants. I consider it more important to remove syntax that's not anymore needed than to remove keywords. In addition to that, conditional variables likeReturn From Keyword Ifmake it possible to create shorter data thanIFandRETURNcombination. That said, it would probably be better to deprecate also all these to have only one way to return in the end. BuiltIn having less keywords wouldn't hurt either.pekkaklarck commentedon Sep 6, 2021
A common use case when returning is to execute a lower level keyword and returning its return value. Because we cannot separate
from
I think its better to just support returning values. If you need to run a keyword and return its return value, it needs to be done separately:
The underlying issue here is that same that it would sometimes be nice to pass keyword return values directly as argument, but we cannot really separate
from
either. We already have #3187 about adding some inline keyword call syntax and it should naturally work with
RETURNas well.pekkaklarck commentedon Sep 14, 2021
This enhancement requires changes on many places starting from the parser and continuing to the execution side. I explain here briefly what's needed on the parsing side and can write separate comment later about changes on the execution side. This information hopefully helps someone interested to contribute and same instructions apply also to
BREAKandCONTINUE(#4079).All this new stuff is needed in parsing:
EndLexer.lexer_classesmethod.Endstatement can be used as an example.test_lexer.py, but that file is so huge it's hard to see where these new tests would fi. The whole flow can be tested with tests intest_model.pyandfrom_paramsmethod should be tested intest_statements.py.MoreFamed commentedon Oct 6, 2021
If we will have inline IF syntax (#4093):
The stuff on the right side looks prettier to me and is always shorter, so I would deprecate all keywords and constructions on the left side. :)
bhirsz commentedon Oct 6, 2021
Note that [Return] does not return anything, it just set what variable should be returned at the end of keyword.
pekkaklarck commentedon Oct 7, 2021
Agreed,
[Return]and allReturn ...keywords should be deprecated. In RF 5.0 that deprecation will only be a note in the docs, though, because it would be annoying to get deprecation warnings in RF 5.0 from syntax that you must use with earlier. We can then consider deprecating these loudly in RF 5.1 or later. There's no big hurry in removing them either. It would be annoying to migrate from RF 4.1 to e.g. RF 5.2 if e.g.[Return]wouldn't work at all in the latter.I expect that RoboTidy and RoboCop can help in transition.
bhirsz commentedon Oct 8, 2021
Yes, we will add deprecation warnings in Robocop (for 5.0) and add transformer in Robotidy for replacing all variants to RETURN
Implement RETURN. (#4078)
Enhance RETURN (#4078)
Enhance tests for RETURN (#4078)
[-]New `RETURN` statement for returning from a user keyword[/-][+]New `RETURN` statement for returning from user keywords[/+]sebastianciupinski commentedon Nov 19, 2021
I am ok with adding RETURN, but I do not think removing [Return] should be considered. It is going to force rewrite thousands of already created resources.
bhirsz commentedon Nov 19, 2021
I already have written transformer in robotidy autoformatting tool that handles it for you (it will be released before 5.0 together with other changes for 5.0). So it should'nt be the issue
pekkaklarck commentedon Nov 19, 2021
[Return]will eventually be removed but it's likely to have quite long deprecation period.RETURN fixes (#4078).
UG: Update kw type info passed to `start/end_keyword` listener methods.
More unit tests for new control structures
Test handling BREAK and CONTINUE (#4079) and RETURN (#4078) after fai…
Add `body` to result side RETURN/BREAK/CONTINUE models
Tim-QA commentedon Sep 27, 2024
In the latest release 2.1.b1, RIDE continues to use the fixed parameter Return Value under Settings. This corresponds to the value [Return] in the text editor. Robot Framework 7.1 shows then the error messages:
The '[Return]' setting is deprecated. Use the 'RETURN' statement instead.
Is there any adjustment to this?