This may be similar to another bug you just fixed. I'm seeing this AttributeError when I try to extract a method.
I can recreate the error using this small bit of code:
with open('asdf', 'w') as f: f.write('asdf') f.write('fdsa')
If I try to extract the two lines in the with-statement, I get the attached stack trace. This is from the "traad" refactoring tool in emacs.
I've verified that traad can extract similar lines that aren't in a with-statement, so I assume that this defect has something specifically to do with with-statements.