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

Return statements inside flattened If nodes #8

Open
Tirasz opened this issue Apr 10, 2022 · 0 comments
Open

Return statements inside flattened If nodes #8

Tirasz opened this issue Apr 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@Tirasz
Copy link
Owner

Tirasz commented Apr 10, 2022

While testing, i found an oversight regarding the logic of "flattening".

I came across something like this:

def foo(obj):
    if isinstance(obj, someClass) and something()
        if something_else():
            return obj.copy()
        return obj

That got turned into:

def foo(obj):
    match obj:
        case SomeClass() if something() and something_else():
            return obj.copy()
            return obj

This is of course wrong. But Im pretty sure its quite easily fixable, with a simple check.
I need to check if there are any return, continue, break, yield keywords inside of the nested if-node.
The whole idea of flattening is based on the fact, that the code before the nested node (Pre-nest), and the code after it (Post-nest) are always getting executed, if the main condition is true. However, if the nested node contains any of the before mentioned keywords, then this is no longer true.
To be safe, I'm only going to allow flattening, if neither the pre and post-nested code segments, neither the nested if-node itself contains any of the return, continue, break, yield keywords.

@Tirasz Tirasz added the bug Something isn't working label Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant