Skip to content

Failing parse on nested with-statements. #104

@Ferada

Description

@Ferada

I've uploaded this commit with two failing teststhis commit with one failing test case which, one just fails to refactor correctly, the other raises an exception because(?) the source code doesn't exactly match the AST, i.e.:

    with open("test") as file1, open("test") as file2:
        print(file1, file2)

fails to parse; there is a second (nested) with node in the AST, but in _Source.consume/patchedast.py:643 the self.offset is at the end of the line and couldn't match a second, non-existent with anyway.

The other, simpler case is a regular nested `with`, i.e. extracting a method from the following code (the `print` line):
    with open("test") as file1:
        with open("test") as file2:
            print(file1, file2)

will refactor (and miss the two variables) to:

    def extracted():
        print(file1, file2)

    with open("test") as file1:
        with open("test") as file2:
            extracted()

I'm pretty sure I can figure out the second case, but for the first I'm at a loss how to start fixing it. Any pointers?

Edit: I've changed the one test case to reflect the working behaviour with the added global_ flag.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions