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_idioms.py generates bad code #47813
Comments
fix_idioms.py generates bad code for conversions in try/except blocks. fix_idioms.py generates this diff:
--- test.py (original)
+++ test.py (refactored)
@@ -7,8 +7,7 @@
s=(1, 2, 3)
try:
- t = list(s)
- t.sort()
-except TypeError:
+ t = sorted(s)
+ except TypeError:
pass
except TypeError is indented wrongly. |
It's due to these lines in fix_idioms: if next_stmt:
next_stmt[0].set_prefix(sort_stmt.get_prefix()) I'm not sure what the correct way to deal with this is. Anyway I'm |
Why is the statement, whatever it is, even being touched? IOW, why not delete that pair of lines from fix_idioms.py? |
I would drop the prefix in that case or attach it to the sorted() call. So from this code: x = foo()
# perform sorting
x.sort() to # perform sorting
x = sorted(foo()) Makes more sense than sticking it after the sorted() call like it |
Attached a patch that implements more thoroughly what appears to be the |
Missed a paren in the last one... re-uploading it. |
Thanks very much for the patch; Committed in r75278. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: