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.
I've uploaded
this commit with two failing teststhis commit with one failing test case which, one just fails to refactor correctly, the otherraises an exception because(?)the source code doesn't exactly match the AST, i.e.:fails to parse; there is a second (nested)
withnode in the AST, but in_Source.consume/patchedast.py:643theself.offsetis at the end of the line and couldn't match a second, non-existentwithanyway.The other, simpler case is a regular nested `with`, i.e. extracting a method from the following code (the `print` line):
will refactor (and miss the two variables) to:
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.