Open hayd opened 10 years ago
Weird edge case, but I don't think indentation is fixed at all with line_range
:
code = 'a = 1\n\ndef f(x):\n a = 1\n def g(x):\n pass\n c = 1\n\na = 1\n\nb = 1\nc = 1'
options = autopep8.parse_args(['--range 6 6']) # 6 is the over-indented pass line
autopep8.fix_code(code, options)
Similarly with 5-7 or even 2-9 indentation is not fixed 4 spaces.
Will investigate a little, I'm not sure where the indentation fixes are being applied (perhaps it's a won't fix).
big PR for this in autopep8 is pending. Will fix almost all of these edge cases (one edge case with comments on there own, i.e. not in a passed range, could look into in the future, not so important IMO).
pr has been merged.
point release is probably in the next week
I thought I fixed the one with comments, but perhaps I was mistaken (it seems to indent them sometimes, when there is no reason to do so). Maybe comments in multi-indented code get indented, IIRC is non-tokenization of comments.
argh, I was sure used to work (indentation would fix in the middle, perhaps this is turned off in autopep8??):
def f(x):
foo() # edit this line, only two spaces
Also (and this is a pretty bad one):
if True:
# edit this comment, then gets indented
do_something()
can't seem to reproduce either..
EDIT: failing example
s = 'if True:\n if True:\n if True:\n # bah\n pass\n'
args = autopep8.parse_args(['', '--range', '4', '5'])
print autopep8.fix_code(s, args)
if True:
if True:
if True:
# bah
pass
Note: autopep8 is safe (conservative), these "bugs" are to make it more aggressive in what it can fix.
Should confirm these/provide tests and pass upstream/fix:
Note: we'll obviously need to require a later version if/once these are fixed!
Consider copying some of my examples in the unittests for range there here.