Skip to content

Commit

Permalink
Fix [Return] not being transformed & fatal exception on RF 7.0rc1 (#610)
Browse files Browse the repository at this point in the history
* Fix return type for resolved arguments

* Fix [Return] not transformed after model change in RF 7.0rc1
  • Loading branch information
bhirsz authored Dec 24, 2023
1 parent 0372450 commit cffe8eb
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/releasenotes/unreleased/fix.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Robot Framework 7.0 backward incompatible changes: TypeError: can only concatenate list (not "tuple") to list
-------------------------------------------------------------------------------------------------------------

Resolving transformers arguments uses Robot Framework argument resolver. Recent change of the return type caused
fatal exception which should be now fixed.
8 changes: 8 additions & 0 deletions docs/releasenotes/unreleased/fix.3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Return] setting deprecated
----------------------------

``[Return]`` setting is now visibly deprecated. The model also changed and several Robotidy transformers stopped
transforming ``[Return]``. We should now be able to handle both ``[Return]`` and ``RETURN``.

Note that Robotidy replaces ``[Return]`` with ``RETURN`` since Robot Framework 5.0 thanks to ``ReplaceReturns``
transformer. If you're not using default configuration you should remember to include it.
2 changes: 1 addition & 1 deletion robotidy/transformers/GenerateDocumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def visit_ReturnStatement(self, node): # noqa
return
self.returns = list(node.values)

visit_Return = visit_ReturnStatement
visit_Return = visit_ReturnSetting = visit_ReturnStatement


class GenerateDocumentation(Transformer):
Expand Down
4 changes: 3 additions & 1 deletion robotidy/transformers/RenameVariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def visit_Setup(self, node): # noqa
data_token.value = self.rename_value(data_token.value, variable_case="auto", is_var=False)
return self.generic_visit(node)

visit_Teardown = visit_Timeout = visit_Template = visit_Return = visit_ReturnStatement = visit_Setup
visit_Teardown = (
visit_Timeout
) = visit_Template = visit_Return = visit_ReturnStatement = visit_ReturnSetting = visit_Setup

@skip_if_disabled
def visit_Variable(self, node): # noqa
Expand Down
2 changes: 2 additions & 0 deletions robotidy/transformers/ReplaceReturns.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def visit_KeywordCall(self, node): # noqa
def visit_Return(self, node): # noqa
self.return_statement = node

visit_ReturnSetting = visit_Return

@skip_if_disabled
def visit_Error(self, node): # noqa
"""Remove duplicate [Return]"""
Expand Down
7 changes: 4 additions & 3 deletions robotidy/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def split_args_to_class_and_skip(args):
return filtered_args, skip_args


def resolve_argument_names(argument_names, handles_skip):
def resolve_argument_names(argument_names: List[str], handles_skip):
"""Get transformer argument names with resolved skip parameters."""
new_args = ["enabled"]
if "skip" not in argument_names:
Expand Down Expand Up @@ -421,12 +421,13 @@ def resolve_args(transformer, spec, args, global_skip, handles_skip):
"skip" parameter the Skip class will be also added to class arguments.
"""
args, skip_args = split_args_to_class_and_skip(args)
argument_names = resolve_argument_names(spec.argument_names, handles_skip)
spec_args = list(spec.argument_names)
argument_names = resolve_argument_names(spec_args, handles_skip)
assert_handled_arguments(transformer, args, argument_names)
try:
positional, named = spec.resolve(args)
named = dict(named)
if "skip" in spec.argument_names:
if "skip" in spec_args:
named["skip"] = get_skip_class(spec, skip_args, global_skip)
return positional, named, argument_names
except ValueError as err:
Expand Down
2 changes: 1 addition & 1 deletion robotidy/transformers/aligners_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def visit_Return(self, node): # noqa
return node
return self.align_node(node, check_length=False)

visit_ReturnStatement = visit_Return
visit_ReturnStatement = visit_ReturnSetting = visit_Return

@skip_if_disabled
def visit_Template(self, node): # noqa
Expand Down
2 changes: 1 addition & 1 deletion tests/rf_versions_matrix/requirements_rf7.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
robotframework==7.0a1
robotframework==7.0rc1

0 comments on commit cffe8eb

Please sign in to comment.