Skip to content

Parse in-line if statements #138

@liamhuber

Description

@liamhuber

When we encounter a typical if-...-else statement, we find anast.If:

def simple_if_else(x, y):
    if my_cond(x, y):  # noqa: SIM108
        z = my_add(x, y)
    else:
        z = my_mul(x, y)
    return z

It would be nice to extend WorkflowParser.handle_assignment to also handle ast.IfExp so we can parse an else-node out of the equivalent python:

def simple_if_else(x, y):
    z = my_add(x, y) if my_cond(x, y) else my_mul(x, y)
    return z

I think such an extension should be quite straightforward. My current understanding is that if we have an assignment available (z above) then it's always possible to reformulate the weaker ast.IfExp back into the more powerful ast.If.

I want to focus on getting the core functionality up for all the control flow parsers before adding sugar to a given flow, so this can wait.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions