-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix_range is not idempotent #52
Comments
I think this might be resolved by turning back on |
That sounds elegant. I'm thinking through it looking for edge cases. |
I think the 2to3 fixer is not quite idempotent. Consider: a = xrange(1, 20)
# Converted to
a = range(1, 20)
# Converted to
a = list(range(1,20)) This only affects an xrange in a non-iterator context, and it only has one extra step before it becomes stable. If we want it to be properly idempotent, we can subclass/copy the fixer and make it skipped if |
I think we should do what @takluyver suggests (subclass the |
BTW we should call the subclass fixer |
Re: "it only has one extra step before it becomes stable" -- yes, but that step is incorrect: if the call was originally to |
+1 for the subclass. This will also be a good test of the approach for things like |
Along the way, move the fixer over to `lib2to3.fixes.fix_xrange` to piggyback on all the work done there. Closes PyCQA#52 .
Now that
libmodernize.fixes.fix_range
is being used instead oflib2to3.fixes.fix_xrange
, there is the problem that the fixer is no longer idempotent, i.e.list(range(1))
will becomelist(list(range(1)))
andfrom six.moves import range; range(1)
becomesfrom six.moves import range; list(range(1))
.Possible solutions are:
range
andxrange
(I suspectrange
is doable with somenot
rule in the pattern, butxrange
might be a pain)xrange
and assume anyone usingrange
to make a list can do the fix themselveslib2to3.fixes.fix_xrange
which turnsxrange
intorange
The text was updated successfully, but these errors were encountered: