Hello community, here is the log from the commit of package python-autopep8 for openSUSE:Factory checked in at 2017-10-17 01:52:06 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-autopep8 (Old) and /work/SRC/openSUSE:Factory/.python-autopep8.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-autopep8" Tue Oct 17 01:52:06 2017 rev:9 rq:533943 version:1.3.3 Changes: -------- --- /work/SRC/openSUSE:Factory/python-autopep8/python-autopep8.changes 2017-08-10 14:13:05.628084589 +0200 +++ /work/SRC/openSUSE:Factory/.python-autopep8.new/python-autopep8.changes 2017-10-17 01:52:08.507491930 +0200 @@ -1,0 +2,18 @@ +Thu Oct 12 22:50:14 UTC 2017 - a...@gmx.de + +- update to version 1.3.3: + * add verbose print for 2to3 fixer (for #325) + * fix test suite output + * for #338 (easy solution...) + * Fix a bug in E305 + * care of corner cases for E713 (maybe, not perfect) + * ignore 'not in' case for E713 + * add test for e713 regression (for #276) + * strict pep8 + * improve w503 fixed method + * more test case for w503 + * consider that w503 with comment (#323) + * add test that w503 with comment + * Avoid a crash when shortening comments + +------------------------------------------------------------------- Old: ---- autopep8-1.3.2.tar.gz New: ---- autopep8-1.3.3.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-autopep8.spec ++++++ --- /var/tmp/diff_new_pack.adsXmS/_old 2017-10-17 01:52:09.307454458 +0200 +++ /var/tmp/diff_new_pack.adsXmS/_new 2017-10-17 01:52:09.311454270 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-autopep8 -Version: 1.3.2 +Version: 1.3.3 Release: 0 Summary: Automatic generated to pep8 checked code License: MIT ++++++ autopep8-1.3.2.tar.gz -> autopep8-1.3.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.3.2/PKG-INFO new/autopep8-1.3.3/PKG-INFO --- old/autopep8-1.3.2/PKG-INFO 2017-05-27 17:22:59.000000000 +0200 +++ new/autopep8-1.3.3/PKG-INFO 2017-10-11 10:18:31.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.3.2 +Version: 1.3.3 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide Home-page: https://github.com/hhatto/autopep8 Author: Hideo Hattori diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.3.2/autopep8.egg-info/PKG-INFO new/autopep8-1.3.3/autopep8.egg-info/PKG-INFO --- old/autopep8-1.3.2/autopep8.egg-info/PKG-INFO 2017-05-27 17:22:59.000000000 +0200 +++ new/autopep8-1.3.3/autopep8.egg-info/PKG-INFO 2017-10-11 10:18:31.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.3.2 +Version: 1.3.3 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide Home-page: https://github.com/hhatto/autopep8 Author: Hideo Hattori diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.3.2/autopep8.py new/autopep8-1.3.3/autopep8.py --- old/autopep8-1.3.2/autopep8.py 2017-05-27 17:20:33.000000000 +0200 +++ new/autopep8-1.3.3/autopep8.py 2017-10-11 10:11:23.000000000 +0200 @@ -66,7 +66,7 @@ unicode = str -__version__ = '1.3.2' +__version__ = '1.3.3' CR = '\r' @@ -77,6 +77,7 @@ PYTHON_SHEBANG_REGEX = re.compile(r'^#!.*\bpython[23]?\b\s*$') LAMBDA_REGEX = re.compile(r'([\w.]+)\s=\slambda\s*([\(\)\w,\s.]*):') COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+([^][)(}{]+)\s+(in|is)\s') +COMPARE_NEGATIVE_REGEX_THROUGH = re.compile(r'\b(not\s+in)\s') BARE_EXCEPT_REGEX = re.compile(r'except\s*:') STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)\s.*\):') @@ -805,6 +806,7 @@ offset -= 1 offset += 1 self.source[offset] = cr + self.source[offset] + return [1 + offset] # Line indexed at 1. def fix_e401(self, result): """Put imports on separate lines.""" @@ -885,12 +887,15 @@ if cache_entry in self.long_line_ignore_cache: return [] - if self.options.aggressive and target.lstrip().startswith('#'): - # Wrap commented lines. - return shorten_comment( - line=target, - max_line_length=self.options.max_line_length, - last_comment=not next_line.lstrip().startswith('#')) + if target.lstrip().startswith('#'): + if self.options.aggressive: + # Wrap commented lines. + return shorten_comment( + line=target, + max_line_length=self.options.max_line_length, + last_comment=not next_line.lstrip().startswith('#')) + else: + return [] fixed = get_fixed_long_line( target=target, @@ -935,7 +940,7 @@ # Avoid applying this when indented. # https://docs.python.org/reference/compound_stmts.html for line in logical_lines: - if ':' in line: + if ':' in line and STARTSWITH_DEF_REGEX.match(line): return [] line_index = result['line'] - 1 @@ -1043,16 +1048,35 @@ def fix_e713(self, result): """Fix (trivial case of) non-membership check.""" - (line_index, _, target) = get_index_offset_contents(result, - self.source) + (line_index, offset, target) = get_index_offset_contents(result, + self.source) + + # to convert once 'not in' -> 'in' + before_target = target[:offset] + target = target[offset:] + match_notin = COMPARE_NEGATIVE_REGEX_THROUGH.search(target) + notin_pos_start, notin_pos_end = 0, 0 + if match_notin: + notin_pos_start = match_notin.start(1) + notin_pos_end = match_notin.end() + target = '{0}{1} {2}'.format( + target[:notin_pos_start], 'in', target[notin_pos_end:]) + # fix 'not in' match = COMPARE_NEGATIVE_REGEX.search(target) if match: if match.group(3) == 'in': pos_start = match.start(1) - self.source[line_index] = '{0}{1} {2} {3} {4}'.format( + new_target = '{5}{0}{1} {2} {3} {4}'.format( target[:pos_start], match.group(2), match.group(1), - match.group(3), target[match.end():]) + match.group(3), target[match.end():], before_target) + if match_notin: + # revert 'in' -> 'not in' + pos_start = notin_pos_start + offset + pos_end = notin_pos_end + offset - 4 # len('not ') + new_target = '{0}{1} {2}'.format( + new_target[:pos_start], 'not in', new_target[pos_end:]) + self.source[line_index] = new_target def fix_e714(self, result): """Fix object identity should be 'is not' case.""" @@ -1117,15 +1141,51 @@ return if not _is_binary_operator(ts[0][0], one_string_token): return + # find comment + comment_index = None + for i in range(5): + # NOTE: try to parse code in 5 times + if (line_index - i) < 0: + break + from_index = line_index - i - 1 + to_index = line_index + 1 + try: + ts = generate_tokens("".join(self.source[from_index:to_index])) + except Exception: + continue + newline_count = 0 + newline_index = [] + for i, t in enumerate(ts): + if t[0] in (tokenize.NEWLINE, tokenize.NL): + newline_index.append(i) + newline_count += 1 + if newline_count > 2: + tts = ts[newline_index[-3]:] + else: + tts = ts + old = None + for t in tts: + if tokenize.COMMENT == t[0]: + if old is None: + comment_index = 0 + else: + comment_index = old[3][1] + break + old = t + break i = target.index(one_string_token) self.source[line_index] = '{0}{1}'.format( target[:i], target[i + len(one_string_token):]) nl = find_newline(self.source[line_index - 1:line_index]) before_line = self.source[line_index - 1] bl = before_line.index(nl) - self.source[line_index - 1] = '{0} {1}{2}'.format( - before_line[:bl], one_string_token, - before_line[bl:]) + if comment_index: + self.source[line_index - 1] = '{0} {1} {2}'.format( + before_line[:comment_index], one_string_token, + before_line[comment_index + 1:]) + else: + self.source[line_index - 1] = '{0} {1}{2}'.format( + before_line[:bl], one_string_token, before_line[bl:]) def get_index_offset_contents(result, source): @@ -1148,6 +1208,7 @@ indent = _get_indentation(target) source = target[len(indent):] assert source.lstrip() == source + assert not target.lstrip().startswith('#') # Check for partial multiline. tokens = list(generate_tokens(source)) @@ -1378,16 +1439,21 @@ return new_text -def code_to_2to3(select, ignore): +def code_to_2to3(select, ignore, where='', verbose=False): fixes = set() for code, fix in CODE_TO_2TO3.items(): if code_match(code, select=select, ignore=ignore): + if verbose: + print('---> Applying {0} fix for {1}'.format(where, + code.upper()), + file=sys.stderr) fixes |= set(fix) return fixes def fix_2to3(source, - aggressive=True, select=None, ignore=None, filename=''): + aggressive=True, select=None, ignore=None, filename='', + where='global', verbose=False): """Fix various deprecated code (via lib2to3).""" if not aggressive: return source @@ -1397,7 +1463,9 @@ return refactor(source, code_to_2to3(select=select, - ignore=ignore), + ignore=ignore, + where=where, + verbose=verbose), filename=filename) @@ -1495,7 +1563,8 @@ lowest_priority = [ # We need to shorten lines last since the logical fixer can get in a # loop, which causes us to exit early. - 'e501' + 'e501', + 'w503' ] key = pep8_result['id'].lower() try: @@ -3176,7 +3245,9 @@ aggressive=options.aggressive, select=options.select, ignore=options.ignore, - filename=filename) + filename=filename, + where=where, + verbose=options.verbose) return source diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.3.2/test/test_autopep8.py new/autopep8-1.3.3/test/test_autopep8.py --- old/autopep8-1.3.2/test/test_autopep8.py 2017-05-06 04:35:35.000000000 +0200 +++ new/autopep8-1.3.3/test/test_autopep8.py 2017-10-11 10:09:28.000000000 +0200 @@ -3199,6 +3199,16 @@ with autopep8_context(line, options=['-aa']) as result: self.assertEqual(fixed, result) + def test_e501_shorten_comment_without_aggressive(self): + """Do nothing without aggressive.""" + line = """\ +def foo(): + pass +# --------- ---------------------------------------------------------------------- +""" + with autopep8_context(line) as result: + self.assertEqual(line, result) + def test_e501_with_aggressive_and_escaped_newline(self): line = """\ if True or \\ @@ -3719,6 +3729,22 @@ with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e702_with_dict_semicolon(self): + line = """\ +MY_CONST = [ + {'A': 1}, + {'B': 2} +]; +""" + fixed = """\ +MY_CONST = [ + {'A': 1}, + {'B': 2} +] +""" + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + def test_e703_with_inline_comment(self): line = 'a = 5; # inline comment\n' fixed = 'a = 5 # inline comment\n' @@ -3841,6 +3867,27 @@ options=['-aa', '--select=E713']) as result: self.assertEqual(fixed, result) + def test_e713_chain(self): + line = 'if "@" not in x or not "/" in y:\n pass\n' + fixed = 'if "@" not in x or "/" not in y:\n pass\n' + with autopep8_context(line, + options=['-aa', '--select=E713']) as result: + self.assertEqual(fixed, result) + + def test_e713_chain2(self): + line = 'if "@" not in x or "[" not in x or not "/" in y:\n pass\n' + fixed = 'if "@" not in x or "[" not in x or "/" not in y:\n pass\n' + with autopep8_context(line, + options=['-aa', '--select=E713']) as result: + self.assertEqual(fixed, result) + + def test_e713_chain3(self): + line = 'if not "@" in x or "[" not in x or not "/" in y:\n pass\n' + fixed = 'if "@" not in x or "[" not in x or "/" not in y:\n pass\n' + with autopep8_context(line, + options=['-aa', '--select=E713']) as result: + self.assertEqual(fixed, result) + def test_e714(self): line = 'if not x is y:\n pass\n' fixed = 'if x is not y:\n pass\n' @@ -4080,6 +4127,30 @@ with autopep8_context(line, options=['-aaa']) as result: self.assertEqual(fixed, result) + def test_w503_with_comment(self): + line = '(width == 0 # this is comment\n + height == 0)\n' + fixed = '(width == 0 + # this is comment\n height == 0)\n' + with autopep8_context(line, options=['-aaa']) as result: + self.assertEqual(fixed, result) + + def test_w503_with_comment_double(self): + line = """\ +( + 1111 # C1 + and 22222222 # C2 + and 333333333333 # C3 +) +""" + fixed = """\ +( + 1111 and # C1 + 22222222 and # C2 + 333333333333 # C3 +) +""" + with autopep8_context(line, options=['-aaa']) 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'