rope
rope copied to clipboard
unsafe refactoring: when extracting method, should detect and raise an error if variable scope cannot be determined
Comment copied from https://github.com/python-rope/rope/pull/380#issuecomment-917687734
One maybe-bug with this refactoring:
def my_func(): for dummy in range(10): i += 1Current extract refactoring implementation produces:
def my_func(): for dummy in range(10): i = aaa() def aaa(): i += 1 return iArguably, the original code was non-sense to begin with, as
iwas undefined. When run, that code would've produced aNameError, so strictly speaking, this refactoring is garbage-in, garbage-out.If
iwas assigned before, such as the below code, the current implementation would have produced correct refactoring:def my_func(): i = 0 for dummy in range(10): i += 1Maybe rope could catch this and refuse to refactor such code.