From cffe8eb427e68392b0f92219257754bd05ef5c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Hirsz?= Date: Sun, 24 Dec 2023 17:27:17 +0100 Subject: [PATCH] Fix [Return] not being transformed & fatal exception on RF 7.0rc1 (#610) * Fix return type for resolved arguments * Fix [Return] not transformed after model change in RF 7.0rc1 --- docs/releasenotes/unreleased/fix.2.rst | 5 +++++ docs/releasenotes/unreleased/fix.3.rst | 8 ++++++++ robotidy/transformers/GenerateDocumentation.py | 2 +- robotidy/transformers/RenameVariables.py | 4 +++- robotidy/transformers/ReplaceReturns.py | 2 ++ robotidy/transformers/__init__.py | 7 ++++--- robotidy/transformers/aligners_core.py | 2 +- tests/rf_versions_matrix/requirements_rf7.txt | 2 +- 8 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 docs/releasenotes/unreleased/fix.2.rst create mode 100644 docs/releasenotes/unreleased/fix.3.rst diff --git a/docs/releasenotes/unreleased/fix.2.rst b/docs/releasenotes/unreleased/fix.2.rst new file mode 100644 index 00000000..abe99fa2 --- /dev/null +++ b/docs/releasenotes/unreleased/fix.2.rst @@ -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. diff --git a/docs/releasenotes/unreleased/fix.3.rst b/docs/releasenotes/unreleased/fix.3.rst new file mode 100644 index 00000000..c100d4c6 --- /dev/null +++ b/docs/releasenotes/unreleased/fix.3.rst @@ -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. diff --git a/robotidy/transformers/GenerateDocumentation.py b/robotidy/transformers/GenerateDocumentation.py index aa4ed01d..af17e02b 100644 --- a/robotidy/transformers/GenerateDocumentation.py +++ b/robotidy/transformers/GenerateDocumentation.py @@ -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): diff --git a/robotidy/transformers/RenameVariables.py b/robotidy/transformers/RenameVariables.py index 12bdd88c..7260e241 100644 --- a/robotidy/transformers/RenameVariables.py +++ b/robotidy/transformers/RenameVariables.py @@ -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 diff --git a/robotidy/transformers/ReplaceReturns.py b/robotidy/transformers/ReplaceReturns.py index 21fa86fb..6437a842 100644 --- a/robotidy/transformers/ReplaceReturns.py +++ b/robotidy/transformers/ReplaceReturns.py @@ -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]""" diff --git a/robotidy/transformers/__init__.py b/robotidy/transformers/__init__.py index ad5656dc..fcc7f35a 100644 --- a/robotidy/transformers/__init__.py +++ b/robotidy/transformers/__init__.py @@ -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: @@ -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: diff --git a/robotidy/transformers/aligners_core.py b/robotidy/transformers/aligners_core.py index 8e4f8102..1a95b076 100644 --- a/robotidy/transformers/aligners_core.py +++ b/robotidy/transformers/aligners_core.py @@ -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 diff --git a/tests/rf_versions_matrix/requirements_rf7.txt b/tests/rf_versions_matrix/requirements_rf7.txt index 9537b90f..982d99d9 100644 --- a/tests/rf_versions_matrix/requirements_rf7.txt +++ b/tests/rf_versions_matrix/requirements_rf7.txt @@ -1 +1 @@ -robotframework==7.0a1 \ No newline at end of file +robotframework==7.0rc1 \ No newline at end of file