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

Skip to content

Parsing differences in try/except statements with get_model and data_only parameter #4208

@d-biehl

Description

@d-biehl

Hi there,

In the new version 5.0 alpha1 there is a difference in parsing code with robot.api.get_model for try/except statements.

Given this piece of code:

import ast
from robot.api.parsing import get_model


test = r"""
*** Test Cases ***
first
    Log    hi   

    TRY
        Fail    huch
    EXCEPT    huch    AS  ${a}
        Log    except ${a}  
    FINALLY
        Log    finally
    END
"""

for node in ast.walk(get_model(test, data_only=False)):
    if node.errors:
        print(node.errors)

If I set the data_only parameter to False (which is the default value) i will get:

("EXCEPT's AS marker must be second to last.", "EXCEPT's AS variable '\n' is invalid.")

which is not correct, because it is valid code. If I set the data_only parameter to True, then everything is ok.

I think the implementation is wrong in this case:

see here

if as_token is not self.tokens[-2]:

The test for the AS token and the variable should not be done by index, because the tokens differs if we are parsing with data_only= False mode.

Also I think the message EXCEPT's AS marker must be second to last. is not really necessary, it should be enough to say that there is no variable or a wrong variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions