Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use assing, not variable, with FOR and TRY/EXCEPT model objects when referring to assigned variables #4708

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

Closed
Snooz82 opened this issue Mar 29, 2023 · 6 comments

Comments

@Snooz82
Copy link
Member

Snooz82 commented Mar 29, 2023

FOR

After tokenising the assigned variable is of type VARIABLE with FOR loops but shall be ASSIGN:

Example:

FOR     ${i}    IN RANGE   10       # ${i} is:  token.type == "VARIABLE"
   Log    ${i}
END

Here is an assignment happening as in:

${i}    Set Variable     1

Therefore VARIABLE would be considered "wrong" here.

TRY/EXCEPT

Similar situation is with EXCEPT AS variables. they are also VARIABLE

Example:

TRY
    Fail     failure message
EXCEPT     AS    ${error}     # ${error} is:  token.type == "VARIABLE"
   Log     my error ${error}
END

Should also be ASSIGN after the AS

Cheers

@Snooz82 Snooz82 changed the title Assigned Variables in FOR statements are VARIABLE but should be ASSIGN token type (Same for EXCEPT AS) Assigned Variables in FOR statements are VARIABLE but should be ASSIGN token type (Same for EXCEPT AS) Mar 29, 2023
@pekkaklarck
Copy link
Member

I agree, ASSIGN would make more sense everywhere where variables are assigned. Easy change but also backwards incompatible so needs to be done in a major version.

@pekkaklarck
Copy link
Member

pekkaklarck commented Sep 5, 2023

Now that we use ASSIGN token type instead of VARIABLE, it would be a good idea to enhance the parsing model so that ForHeader.variables is renamed to ForHeader.assign and ExceptHeader.variable to ExceptHeader.assign. Old propertys should be preserved but be deprecated.

Need to also think should we change the running and results models the same way.

@pekkaklarck pekkaklarck reopened this Sep 5, 2023
@pekkaklarck pekkaklarck changed the title Assigned Variables in FOR statements are VARIABLE but should be ASSIGN token type (Same for EXCEPT AS) Use assing, not variable, with FOR and TRY/EXCEPT when referring to assigned variables Sep 6, 2023
@pekkaklarck
Copy link
Member

I've now locally done the parsing model change I mentioned above. I like the consistency with property names and token types. We also already used assign property with keyword calls and inline IF so there's even more consistency.

I've also started changing the running and result models to use assign instead of variables or variable. Also that change looks good both in general and for consistency reasons. Unfortunately it also makes this change even more backwards incompatible. I'll list those changes separately when everything is ready.

@pekkaklarck pekkaklarck changed the title Use assing, not variable, with FOR and TRY/EXCEPT when referring to assigned variables Use assing, not variable, with FOR and TRY/EXCEPT model objects when referring to assigned variables Sep 6, 2023
@pekkaklarck
Copy link
Member

pekkaklarck commented Sep 6, 2023

I now ought to have all models updated locally and will commit and push changes after I've gone through changes once more. I try to list all backwards incompatible changes and deprecations caused by this issue below:

  • Token type of variables associated with FOR and EXCEPT has been changed from VARIABLE to ASSIGN. This was the original requests in this issue.
  • Parsing model objects For, Try, ForHeader and ExceptHeader nowadays have values of the aforementioned tokens available via property assign. Earlier the property was variables with FOR and variable with TRY. Old propertys still exist but they are deprecated.
  • Execution and result model objects related to FOR and EXCEPT now have assign attribute. The old variables and variable propertys are preserved but deprecated.
  • Execution and result models objects related to FOR and EXCEPT accept assign, not variables or variable, when initialized.
  • In output.xml possible EXCEPT assignment is now in attribute assign of the <branch> element when it earlier was in variable. FOR variables are still in <var> elements that also keyword calls use. Old output.xml files using the variable attribute are supported, but new output.xml files aren't compatible with previous Robot versions.
  • JSON serialization of the running model (Support serializing executable suite into JSON #3902) now uses assign with FOR and EXCEPT variables instead of earlier variables and variable. Old format is still supported when when processing JSON, but new JSON outputs aren't compatible with previous Robot versions.

pekkaklarck added a commit that referenced this issue Sep 6, 2023
The underlying token types have been changed from `VARIABLE` to
`ASSIGN` already earlier as part of #4708. Propertys accessing token
values are now renamed for consistency as well. We also use `assign`
property with keyword calls and inline IF.

Old propertys are preserved for backwards compatibility reasons, but
they are deprecated. Also arguments to related `from_params` methods
were updated making #4708 a bit more backwards incompatible.
@pekkaklarck
Copy link
Member

Hmm, we still use Token.VARIABLE with variables created in the Variables section and with the new VAR syntax (#3761). That's somewhat inconsistent, but changing the former would be hard because Token.VARIABLE is also the type of the Variable statement and the statement type not being used by the statement tokens would be somewhat odd and also complicate parsing a bit. Need to think about this.

@pekkaklarck
Copy link
Member

After discussion on Slack involving also @Snooz82, we decided to revert the token type changes in RF 7.0. In addition to the inconsistency mentioned above, there are some other issues with token types. We won't have time to go through them all now, and making some changes now and more later would add more work for external tool developers. Better to do this properly in one go. I'll submit a separate issue about that to RF 8.0.

Notice that the model changes are preserved. They aren't backwards incompatible because the old propertys are preserved (but deprecated).

pekkaklarck added a commit that referenced this issue Oct 26, 2023
We had changed the token type used with FOR variables and with
EXCEPT's AS variable from VARIABLE to ASSIGN for them to be consistent
with variables assigned with keyword calls. It later turned out that
we still use VARIABLE in other places for similar purposes so
inconsistency remains. In addition to that, we have noticed some other
inconsistencies and problems with token types. We don't have time to
properly go through them all now in RF 7. Better to postpone this to
RF 8 altogether so that we aren't making backwards incompatible token
type changes in every release.

Also some error message tuning.
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

3 participants