packages/python/autopep8/pycodestyle-2.10.patch

522 lines
19 KiB
Diff

From f9149e1d7477b7d5f08e38e94112b837eed6973f Mon Sep 17 00:00:00 2001
From: Hideo Hattori <hhatto.jp@gmail.com>
Date: Tue, 29 Nov 2022 14:54:29 +0900
Subject: [PATCH 1/5] require pycodestyle 2.10.0 and higher version
---
setup.py | 2 +-
test/test_autopep8.py | 291 ------------------------------------------
2 files changed, 1 insertion(+), 292 deletions(-)
diff --git a/setup.py b/setup.py
index 9c6c377c..ba5c8f31 100755
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@
INSTALL_REQUIRES = (
- ['pycodestyle >= 2.9.1', 'tomli']
+ ['pycodestyle >= 2.10.0', 'tomli']
)
diff --git a/test/test_autopep8.py b/test/test_autopep8.py
index 7efc2db5..8d9af281 100755
--- a/test/test_autopep8.py
+++ b/test/test_autopep8.py
@@ -324,10 +324,6 @@ def test_fix_code_with_options(self):
'print( 123 )\n',
autopep8.fix_code('print( 123 )\n', options={'ignore': ['E']}))
- self.assertEqual(
- 'y in x\n',
- autopep8.fix_code('x.has_key(y)\n', options={'aggressive': True}))
-
def test_fix_code_with_bad_options(self):
with self.assertRaises(ValueError):
autopep8.fix_code('print( 123 )\n', options={'ignor': ['W']})
@@ -712,16 +708,6 @@ def test_count_unbalanced_brackets(self):
autopep8.count_unbalanced_brackets(
"'','.join(['%s=%s' % (col, col)')"))
- def test_refactor_with_2to3(self):
- self.assertEqual(
- '1 in {}\n',
- autopep8.refactor_with_2to3('{}.has_key(1)\n', ['has_key']))
-
- def test_refactor_with_2to3_should_handle_syntax_error_gracefully(self):
- self.assertEqual(
- '{}.has_key(1\n',
- autopep8.refactor_with_2to3('{}.has_key(1\n', ['has_key']))
-
def test_commented_out_code_lines(self):
self.assertEqual(
[1, 4],
@@ -4848,283 +4834,6 @@ def test_w503_and_w504_conflict(self):
with autopep8_context(line, options=['-aa', '--select=E,W50']) as result:
self.assertEqual(fixed, result)
- def test_w601(self):
- line = 'a = {0: 1}\na.has_key(0)\n'
- fixed = 'a = {0: 1}\n0 in a\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_word(self):
- line = 'my_dict = {0: 1}\nmy_dict.has_key(0)\n'
- fixed = 'my_dict = {0: 1}\n0 in my_dict\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_conditional(self):
- line = 'a = {0: 1}\nif a.has_key(0):\n print 1\n'
- fixed = 'a = {0: 1}\nif 0 in a:\n print 1\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_self(self):
- line = 'self.a.has_key(0)\n'
- fixed = '0 in self.a\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_self_with_conditional(self):
- line = 'if self.a.has_key(0):\n print 1\n'
- fixed = 'if 0 in self.a:\n print 1\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_with_multiple(self):
- line = 'a.has_key(0) and b.has_key(0)\n'
- fixed = '0 in a and 0 in b\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_with_multiple_nested(self):
- line = 'alpha.has_key(nested.has_key(12)) and beta.has_key(1)\n'
- fixed = '(12 in nested) in alpha and 1 in beta\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_with_more_complexity(self):
- line = 'y.has_key(0) + x.has_key(x.has_key(0) + x.has_key(x.has_key(0) + x.has_key(1)))\n'
- fixed = '(0 in y) + ((0 in x) + ((0 in x) + (1 in x) in x) in x)\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_precedence(self):
- line = 'if self.a.has_key(1 + 2):\n print 1\n'
- fixed = 'if 1 + 2 in self.a:\n print 1\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_with_parens(self):
- line = 'foo(12) in alpha\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w601_with_multiline(self):
- line = """\
-a.has_key(
- 0
-)
-"""
- fixed = '0 in a\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w601_with_non_ascii(self):
- line = """\
-# -*- coding: utf-8 -*-
-## éはe
-correct = dict().has_key('good syntax ?')
-"""
-
- fixed = """\
-# -*- coding: utf-8 -*-
-# éはe
-correct = 'good syntax ?' in dict()
-"""
-
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_arg_is_string(self):
- line = "raise ValueError, \"w602 test\"\n"
- fixed = "raise ValueError(\"w602 test\")\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_arg_is_string_with_comment(self):
- line = "raise ValueError, \"w602 test\" # comment\n"
- fixed = "raise ValueError(\"w602 test\") # comment\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_skip_ambiguous_case(self):
- line = "raise 'a', 'b', 'c'\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w602_with_logic(self):
- line = "raise TypeError, e or 'hello'\n"
- fixed = "raise TypeError(e or 'hello')\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_triple_quotes(self):
- line = 'raise ValueError, """hello"""\n1\n'
- fixed = 'raise ValueError("""hello""")\n1\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline(self):
- line = 'raise ValueError, """\nhello"""\n'
- fixed = 'raise ValueError("""\nhello""")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_with_complex_multiline(self):
- line = 'raise ValueError, """\nhello %s %s""" % (\n 1, 2)\n'
- fixed = 'raise ValueError("""\nhello %s %s""" % (\n 1, 2))\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_with_trailing_spaces(self):
- line = 'raise ValueError, """\nhello""" \n'
- fixed = 'raise ValueError("""\nhello""")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_with_escaped_newline(self):
- line = 'raise ValueError, \\\n"""\nhello"""\n'
- fixed = 'raise ValueError("""\nhello""")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_with_escaped_newline_and_comment(self):
- line = 'raise ValueError, \\\n"""\nhello""" # comment\n'
- fixed = 'raise ValueError("""\nhello""") # comment\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_with_multiple_escaped_newlines(self):
- line = 'raise ValueError, \\\n\\\n\\\n"""\nhello"""\n'
- fixed = 'raise ValueError("""\nhello""")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_with_nested_quotes(self):
- line = 'raise ValueError, """hello\'\'\'blah"a"b"c"""\n'
- fixed = 'raise ValueError("""hello\'\'\'blah"a"b"c""")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_with_multiline_with_single_quotes(self):
- line = "raise ValueError, '''\nhello'''\n"
- fixed = "raise ValueError('''\nhello''')\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiline_string_stays_the_same(self):
- line = 'raise """\nhello"""\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w602_escaped_lf(self):
- line = 'raise ValueError, \\\n"hello"\n'
- fixed = 'raise ValueError("hello")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_escaped_crlf(self):
- line = 'raise ValueError, \\\r\n"hello"\r\n'
- fixed = 'raise ValueError("hello")\r\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_indentation(self):
- line = 'def foo():\n raise ValueError, "hello"\n'
- fixed = 'def foo():\n raise ValueError("hello")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_escaped_cr(self):
- line = 'raise ValueError, \\\r"hello"\n\n'
- fixed = 'raise ValueError("hello")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_multiple_statements(self):
- line = 'raise ValueError, "hello";print 1\n'
- fixed = 'raise ValueError("hello")\nprint 1\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_raise_argument_with_indentation(self):
- line = 'if True:\n raise ValueError, "error"\n'
- fixed = 'if True:\n raise ValueError("error")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_skip_raise_argument_triple(self):
- line = 'raise ValueError, "info", traceback\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w602_skip_raise_argument_triple_with_comment(self):
- line = 'raise ValueError, "info", traceback # comment\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w602_raise_argument_triple_fake(self):
- line = 'raise ValueError, "info, info2"\n'
- fixed = 'raise ValueError("info, info2")\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_with_list_comprehension(self):
- line = 'raise Error, [x[0] for x in probs]\n'
- fixed = 'raise Error([x[0] for x in probs])\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w602_with_bad_syntax(self):
- line = "raise Error, 'abc\n"
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- def test_w602_invalid_2to3_fixed_case(self):
- line = """\
-raise (ValueError
- if True else TypeError)
-"""
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(line, result)
-
- @unittest.skip('TODO')
- def test_w602_invalid_2to3_fixed_case_with_valid_syntax(self):
- line = """\
-raise (ValueError
- if True else TypeError)
-raise ValueError, "error"
-"""
- fixed = """\
-raise (ValueError
- if True else TypeError)
-raise ValueError("error")
-"""
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w603(self):
- line = 'if 2 <> 2:\n print False'
- fixed = 'if 2 != 2:\n print False\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w604(self):
- line = '`1`\n'
- fixed = 'repr(1)\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w604_with_multiple_instances(self):
- line = '``1`` + ``b``\n'
- fixed = 'repr(repr(1)) + repr(repr(b))\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
- def test_w604_with_multiple_lines(self):
- line = '`(1\n )`\n'
- fixed = 'repr((1\n ))\n'
- with autopep8_context(line, options=['--aggressive']) as result:
- self.assertEqual(fixed, result)
-
def test_w605_simple(self):
line = "escape = '\\.jpg'\n"
fixed = "escape = '\\\\.jpg'\n"
From 25eda3ff05b32b96fb2bf3652664746dc806b27e Mon Sep 17 00:00:00 2001
From: Hideo Hattori <hhatto.jp@gmail.com>
Date: Tue, 29 Nov 2022 15:04:18 +0900
Subject: [PATCH 2/5] remove: w602 fixed method
---
autopep8.py | 8 --------
1 file changed, 8 deletions(-)
diff --git a/autopep8.py b/autopep8.py
index 61b37e33..c03cf756 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -1779,14 +1779,6 @@ def fix_2to3(source,
filename=filename)
-def fix_w602(source, aggressive=True):
- """Fix deprecated form of raising exception."""
- if not aggressive:
- return source
-
- return refactor(source, ['raise'], ignore='with_traceback')
-
-
def find_newline(source):
"""Return type of newline used in source.
From a7e7c9a97469b9bd999540240b17de18e7137d27 Mon Sep 17 00:00:00 2001
From: Hideo Hattori <hhatto.jp@gmail.com>
Date: Tue, 29 Nov 2022 16:19:06 +0900
Subject: [PATCH 3/5] remove global fixes
---
autopep8.py | 13 +------------
test/test_autopep8.py | 8 ++++----
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/autopep8.py b/autopep8.py
index c03cf756..92dae70d 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -129,15 +129,10 @@ class documentation for more information.
# to be enabled, disable both of them
CONFLICTING_CODES = ('W503', 'W504')
-SELECTED_GLOBAL_FIXED_METHOD_CODES = ['W602', ]
-
# W602 is handled separately due to the need to avoid "with_traceback".
CODE_TO_2TO3 = {
'E231': ['ws_comma'],
'E721': ['idioms'],
- 'W601': ['has_key'],
- 'W603': ['ne'],
- 'W604': ['repr'],
'W690': ['apply',
'except',
'exitfunc',
@@ -3548,13 +3543,10 @@ def fix_lines(source_lines, options, filename=''):
sio = io.StringIO(tmp_source)
contents = sio.readlines()
results = _execute_pep8(pep8_options, contents)
- codes = {result['id'] for result in results
- if result['id'] in SELECTED_GLOBAL_FIXED_METHOD_CODES}
# Apply global fixes only once (for efficiency).
fixed_source = apply_global_fixes(tmp_source,
options,
- filename=filename,
- codes=codes)
+ filename=filename)
passes = 0
long_line_ignore_cache = set()
@@ -3676,9 +3668,6 @@ def apply_global_fixes(source, options, where='global', filename='',
)
for (code, function) in global_fixes():
- if code.upper() in SELECTED_GLOBAL_FIXED_METHOD_CODES \
- and code.upper() not in codes:
- continue
if code_match(code, select=options.select, ignore=options.ignore):
if options.verbose:
print('---> Applying {} fix for {}'.format(where,
diff --git a/test/test_autopep8.py b/test/test_autopep8.py
index 8d9af281..64d30eb2 100755
--- a/test/test_autopep8.py
+++ b/test/test_autopep8.py
@@ -978,11 +978,11 @@ def test_e101_when_pep8_mistakes_first_tab_in_string(self):
def test_e101_should_ignore_multiline_strings_complex(self):
line = """\
-print(3 <> 4, '''
+print(3 != 4, '''
while True:
if True:
\t1
-\t''', 4 <> 5)
+\t''', 4 != 5)
"""
fixed = """\
print(3 != 4, '''
@@ -4430,11 +4430,11 @@ def test_should_preserve_vertical_tab(self):
def test_w191_should_ignore_multiline_strings(self):
line = """\
-print(3 <> 4, '''
+print(3 != 4, '''
while True:
if True:
\t1
-\t''', 4 <> 5)
+\t''', 4 != 5)
if True:
\t123
"""
From bc6ceabd6e9b284bf0c7c49c4160f1c82adda727 Mon Sep 17 00:00:00 2001
From: Hideo Hattori <hhatto.jp@gmail.com>
Date: Tue, 29 Nov 2022 16:22:03 +0900
Subject: [PATCH 4/5] strict flake8
---
autopep8.py | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/autopep8.py b/autopep8.py
index 92dae70d..da427ecb 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -3534,15 +3534,6 @@ def fix_lines(source_lines, options, filename=''):
# Disable "apply_local_fixes()" for now due to issue #175.
fixed_source = tmp_source
else:
- pep8_options = {
- 'ignore': options.ignore,
- 'select': options.select,
- 'max_line_length': options.max_line_length,
- 'hang_closing': options.hang_closing,
- }
- sio = io.StringIO(tmp_source)
- contents = sio.readlines()
- results = _execute_pep8(pep8_options, contents)
# Apply global fixes only once (for efficiency).
fixed_source = apply_global_fixes(tmp_source,
options,
From 2b1ead2e362ea058662b7f71e18fed38b07d8e23 Mon Sep 17 00:00:00 2001
From: Hideo Hattori <hhatto.jp@gmail.com>
Date: Tue, 29 Nov 2022 16:28:31 +0900
Subject: [PATCH 5/5] update readme
---
README.rst | 7 -------
1 file changed, 7 deletions(-)
diff --git a/README.rst b/README.rst
index d1c2d759..a65dba1c 100644
--- a/README.rst
+++ b/README.rst
@@ -245,10 +245,6 @@ autopep8 fixes the following issues_ reported by pycodestyle_::
W391 - Remove trailing blank lines.
W503 - Fix line break before binary operator.
W504 - Fix line break after binary operator.
- W601 - Use "in" rather than "has_key()".
- W602 - Fix deprecated form of raising exception.
- W603 - Use "!=" instead of "<>"
- W604 - Use "repr()" instead of backticks.
W605 - Fix invalid escape sequence 'x'.
W690 - Fix various deprecated code (via lib2to3).
@@ -347,9 +343,6 @@ function:
Or with options:
>>> import autopep8
- >>> autopep8.fix_code('x.has_key(y)\n',
- ... options={'aggressive': 1})
- 'y in x\n'
>>> autopep8.fix_code('print( 123 )\n',
... options={'ignore': ['E']})
'print( 123 )\n'