Permalink
Browse files

featured: W602 fixed method

  • Loading branch information...
1 parent b311cf8 commit b65efc4efeeb8e765f4eb2723f860dc682760bb4 @hhatto committed Dec 5, 2011
Showing with 35 additions and 17 deletions.
  1. +32 −17 autopep8.py
  2. +3 −0 test_target.py
View
@@ -32,23 +32,18 @@ class FixPEP8(object):
"""fix invalid code
[fixed method list]
- - e201
- - e203
- - e211
- - e225
- - e231
- - e251
- - e261
- - e262
- - e301
- - e302
- - e303
- - e401
- - e701
- - e702
- - w291
- - w293
- - w391
+ - e201,e202,e203
+ - e211
+ - e221,e225
+ - e231
+ - e251
+ - e261,e262
+ - e301,e302,e303
+ - e401
+ - e701,e702
+ - w291,w293
+ - w391
+ - w602
"""
def __init__(self, filename, options):
self.filename = filename
@@ -316,6 +311,26 @@ def fix_w391(self, result):
def fix_w601(self, result):
pass
+ def fix_w602(self, result):
+ line = self.source[result['line'] - 1]
+ sio = StringIO(line)
+ fixed_line = ""
+ is_found_raise = False
+ for tokens in tokenize.generate_tokens(sio.readline):
+ if tokens[0] is token.INDENT:
+ fixed_line += tokens[1]
+ elif tokens[1] == 'raise':
+ fixed_line += "raise "
+ is_found_raise = True
+ elif tokens[0] is token.NAME and is_found_raise:
+ fixed_line += "%s(" % tokens[1]
+ elif tokens[0] is token.NEWLINE:
+ fixed_line += ")%s" % tokens[1]
+ break
+ elif tokens[0] not in (token.OP, token.DEDENT):
+ fixed_line += tokens[1]
+ self.source[result['line'] - 1] = fixed_line
+
def _get_difftext(old, new, filename):
diff = unified_diff(old, new, 'original/' + filename, 'fixed/' + filename)
View
@@ -114,5 +114,8 @@ def func_e702():
4; 5;
+def func_w602():
+ raise ValueError, "w602 test"
+
if __name__ == '__main__': func_last()

0 comments on commit b65efc4

Please sign in to comment.