Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing model: Rename Return to ReturnSetting and ReturnStatement to Return #4939

Closed
pekkaklarck opened this issue Nov 10, 2023 · 0 comments
Closed

Comments

@pekkaklarck
Copy link
Member

pekkaklarck commented Nov 10, 2023

The deprecated [Return] setting is currently represented in the parsing model using a Return class and the RETURN statement is represented as ReturnStatement. For consistency with other control structures, it's better to change this so that Return represents RETURN and [Return] is represented by ReturnSetting. We already added ReturnSetting as a forwards compatible alias for Return in RF 6.1 (#4656) exactly for this purpose. The ModelVisitor base class also support visit_ReturnSetting already now.

In practice this is what needs to be done:

  • Rename Return to ReturnSetting and remove the current ReturnSetting alias.
  • Rename ReturnStatement to Return.
  • Add ReturnStatement alias for backwards compatibility.
  • Add support for visit_ReturnStatement to the ModelVisitor. It will be called with Return nodes if visit_Return is missing.

This is a backwards incompatible change and tools working with the parsing model need to be updated. When using ModelVisitor, the following code ought to work with all versions. If only RF 6.1 or newer needs to be supported, visit_Return isn't needed because Robot will automatically call appropriate visit_ReturnXxx method.

from robot import __version__ as robot_version
from robot.api.parsing import ModelVisitor


RF7_OR_NEWER = int(robot_version.split('.')[0]) >= 7


class Example(ModelVisitor):

    def visit_Return(self, node):
        if RF7_OR_NEWER:
            self.visit_ReturnStatement(node)
        else:
            self.visit_ReturnSetting(node)

    def visit_ReturnStatement(self, node):
        ...

    def visit_ReturnSetting(self, node):
        ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant