commit python3-autopep8 for openSUSE:Factory
Hello community, here is the log from the commit of package python3-autopep8 for openSUSE:Factory checked in at 2015-08-11 08:26:24 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python3-autopep8 (Old) and /work/SRC/openSUSE:Factory/.python3-autopep8.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python3-autopep8" Changes: -------- --- /work/SRC/openSUSE:Factory/python3-autopep8/python3-autopep8.changes 2015-02-27 11:10:21.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.python3-autopep8.new/python3-autopep8.changes 2015-08-11 08:26:28.000000000 +0200 @@ -1,0 +2,48 @@ +Sun Aug 9 00:13:00 UTC 2015 - arun@gmx.de + +- specfile: add AUTHORS.rst file + +- update to version 1.2: + * exec update_readme.py + * Expose "argv" + * Use new pep8 URL + * Clean up + * Generalize to handle dots in E712 and E713 + * Document limitations + * Remove unused tests + * Use actual parameter name + * Strip whitespace in error codes + * Support multiprocessing on Windows + * Avoid issue #175 for now + * Make this work on Python 2.6 + * Remove unnecessary check + * Disable for now + * Add failing example + * Use same version of Python throughout + * Indent + * Fix #183 + * Fix some of #195 + * Clean up import + * Clean up variable names + * Add "--line-range" for consistent naming + * Check for bad options + * Update for dictionary-option change + * Support dictionary options + * Add test for issue #175 + * Narrow down the bug avoidance + * Avoid buggy "--range" case for now + * Separate W391 from global fix + * Avoid breaking lambda at awkward location + * Generalize + * Avoid breaking after unary operator + * Move the "rstrip()" to a better place + * Avoid add trailing in double aggressive mode + * Avoid growing the line length + * Remove redundant option + * Put code in main function + * Support Python 3 in Vim usage example + * Set for bb81d1922970c485edd5dd75f279120c709dc1fe + * Modify E309 to reflect change in PEP 257 + * Update with latest pep8 + +------------------------------------------------------------------- Old: ---- autopep8-1.1.1.tar.gz New: ---- autopep8-1.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python3-autopep8.spec ++++++ --- /var/tmp/diff_new_pack.K5ZDzy/_old 2015-08-11 08:26:29.000000000 +0200 +++ /var/tmp/diff_new_pack.K5ZDzy/_new 2015-08-11 08:26:29.000000000 +0200 @@ -17,7 +17,7 @@ Name: python3-autopep8 -Version: 1.1.1 +Version: 1.2 Release: 0 Url: https://github.com/hhatto/autopep8 Summary: Automatic generated to pep8 checked code @@ -70,7 +70,7 @@ %files %defattr(-,root,root,-) -%doc README.rst +%doc README.rst AUTHORS.rst %ghost %{_bindir}/autopep8 %if 0%{?suse_version} >= 1230 %ghost %{_sysconfdir}/alternatives/autopep8 ++++++ autopep8-1.1.1.tar.gz -> autopep8-1.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/PKG-INFO new/autopep8-1.2/PKG-INFO --- old/autopep8-1.1.1/PKG-INFO 2015-02-26 06:58:32.000000000 +0100 +++ new/autopep8-1.2/PKG-INFO 2015-07-27 06:41:08.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.1.1 +Version: 1.2 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 @@ -42,7 +42,7 @@ autopep8 requires pep8_. - .. _pep8: https://github.com/jcrocholl/pep8 + .. _pep8: https://github.com/PyCQA/pep8 Usage @@ -136,7 +136,7 @@ [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] - [--range line line] [--indent-size n] + [--line-range line line] [--indent-size n] [files [files ...]] Automatically formats Python code to conform to the PEP 8 style guide. @@ -175,7 +175,8 @@ --ignore errors do not fix these errors/warnings (default: E24) --select errors fix only these errors/warnings (e.g. E4,W) --max-line-length n set maximum allowed line length (default: 79) - --range line line only fix errors found within this inclusive range of + --line-range line line, --range line line + only fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers are indexed at 1 --indent-size n number of spaces per indent level (default 4) @@ -300,18 +301,21 @@ =============== The simplest way of using autopep8 as a module is via the ``fix_code()`` - function. + function: - >>> import autopep8 - >>> autopep8.fix_code('x= 123\n') - 'x = 123\n' - - Or with command-line options: - - >>> import autopep8 - >>> autopep8.fix_code('x.has_key(y)\n', - ... options=autopep8.parse_args(['--aggressive', ''])) - 'y in x\n' + >>> import autopep8 + >>> autopep8.fix_code('x= 123\n') + 'x = 123\n' + + 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' Testing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/README.rst new/autopep8-1.2/README.rst --- old/autopep8-1.1.1/README.rst 2014-12-25 03:20:09.000000000 +0100 +++ new/autopep8-1.2/README.rst 2015-07-22 07:30:55.000000000 +0200 @@ -34,7 +34,7 @@ autopep8 requires pep8_. -.. _pep8: https://github.com/jcrocholl/pep8 +.. _pep8: https://github.com/PyCQA/pep8 Usage @@ -128,7 +128,7 @@ [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] - [--range line line] [--indent-size n] + [--line-range line line] [--indent-size n] [files [files ...]] Automatically formats Python code to conform to the PEP 8 style guide. @@ -167,7 +167,8 @@ --ignore errors do not fix these errors/warnings (default: E24) --select errors fix only these errors/warnings (e.g. E4,W) --max-line-length n set maximum allowed line length (default: 79) - --range line line only fix errors found within this inclusive range of + --line-range line line, --range line line + only fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers are indexed at 1 --indent-size n number of spaces per indent level (default 4) @@ -292,18 +293,21 @@ =============== The simplest way of using autopep8 as a module is via the ``fix_code()`` -function. +function: ->>> import autopep8 ->>> autopep8.fix_code('x= 123\n') -'x = 123\n' - -Or with command-line options: - ->>> import autopep8 ->>> autopep8.fix_code('x.has_key(y)\n', -... options=autopep8.parse_args(['--aggressive', ''])) -'y in x\n' + >>> import autopep8 + >>> autopep8.fix_code('x= 123\n') + 'x = 123\n' + +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' Testing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/autopep8.egg-info/PKG-INFO new/autopep8-1.2/autopep8.egg-info/PKG-INFO --- old/autopep8-1.1.1/autopep8.egg-info/PKG-INFO 2015-02-26 06:58:32.000000000 +0100 +++ new/autopep8-1.2/autopep8.egg-info/PKG-INFO 2015-07-27 06:41:08.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.1.1 +Version: 1.2 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 @@ -42,7 +42,7 @@ autopep8 requires pep8_. - .. _pep8: https://github.com/jcrocholl/pep8 + .. _pep8: https://github.com/PyCQA/pep8 Usage @@ -136,7 +136,7 @@ [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] - [--range line line] [--indent-size n] + [--line-range line line] [--indent-size n] [files [files ...]] Automatically formats Python code to conform to the PEP 8 style guide. @@ -175,7 +175,8 @@ --ignore errors do not fix these errors/warnings (default: E24) --select errors fix only these errors/warnings (e.g. E4,W) --max-line-length n set maximum allowed line length (default: 79) - --range line line only fix errors found within this inclusive range of + --line-range line line, --range line line + only fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers are indexed at 1 --indent-size n number of spaces per indent level (default 4) @@ -300,18 +301,21 @@ =============== The simplest way of using autopep8 as a module is via the ``fix_code()`` - function. + function: - >>> import autopep8 - >>> autopep8.fix_code('x= 123\n') - 'x = 123\n' - - Or with command-line options: - - >>> import autopep8 - >>> autopep8.fix_code('x.has_key(y)\n', - ... options=autopep8.parse_args(['--aggressive', ''])) - 'y in x\n' + >>> import autopep8 + >>> autopep8.fix_code('x= 123\n') + 'x = 123\n' + + 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' Testing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/autopep8.egg-info/SOURCES.txt new/autopep8-1.2/autopep8.egg-info/SOURCES.txt --- old/autopep8-1.1.1/autopep8.egg-info/SOURCES.txt 2015-02-26 06:58:32.000000000 +0100 +++ new/autopep8-1.2/autopep8.egg-info/SOURCES.txt 2015-07-27 06:41:08.000000000 +0200 @@ -3,13 +3,13 @@ MANIFEST.in README.rst autopep8.py -setup.cfg setup.py autopep8.egg-info/PKG-INFO autopep8.egg-info/SOURCES.txt autopep8.egg-info/dependency_links.txt autopep8.egg-info/entry_points.txt autopep8.egg-info/not-zip-safe +autopep8.egg-info/pbr.json autopep8.egg-info/requires.txt autopep8.egg-info/top_level.txt test/__init__.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/autopep8.egg-info/pbr.json new/autopep8-1.2/autopep8.egg-info/pbr.json --- old/autopep8-1.1.1/autopep8.egg-info/pbr.json 1970-01-01 01:00:00.000000000 +0100 +++ new/autopep8-1.2/autopep8.egg-info/pbr.json 2015-07-27 06:41:08.000000000 +0200 @@ -0,0 +1 @@ +{"is_release": false, "git_version": "eb6c788"} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/autopep8.py new/autopep8-1.2/autopep8.py --- old/autopep8-1.1.1/autopep8.py 2015-02-26 06:57:06.000000000 +0100 +++ new/autopep8-1.2/autopep8.py 2015-07-27 06:40:16.000000000 +0200 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# + # Copyright (C) 2010-2011 Hideo Hattori # Copyright (C) 2011-2013 Hideo Hattori, Steven Myint # Copyright (C) 2013-2015 Hideo Hattori, Steven Myint, Bill Wendling @@ -40,7 +40,6 @@ from __future__ import print_function from __future__ import unicode_literals -import bisect import codecs import collections import copy @@ -48,13 +47,13 @@ import fnmatch import inspect import io -import itertools import keyword import locale import os import re import signal import sys +import textwrap import token import tokenize @@ -67,7 +66,7 @@ unicode = str -__version__ = '1.1.1' +__version__ = '1.2' CR = '\r' @@ -161,10 +160,7 @@ previous_logical): """Check for missing blank lines after class declaration.""" if previous_logical.startswith('class '): - if ( - logical_line.startswith(('def ', 'class ', '@')) or - pep8.DOCSTRING_REGEX.match(logical_line) - ): + if logical_line.startswith(('def ', 'class ', '@')): if indent_level and not blank_lines and not blank_before: yield (0, 'E309 expected 1 blank line after class declaration') elif previous_logical.startswith('def '): @@ -855,8 +851,8 @@ def fix_e502(self, result): """Remove extraneous escape of newline.""" - line_index = result['line'] - 1 - target = self.source[line_index] + (line_index, _, target) = get_index_offset_contents(result, + self.source) self.source[line_index] = target.rstrip('\n\r \t\\') + '\n' def fix_e701(self, result): @@ -908,9 +904,8 @@ def fix_e711(self, result): """Fix comparison with None.""" - line_index = result['line'] - 1 - target = self.source[line_index] - offset = result['column'] - 1 + (line_index, offset, target) = get_index_offset_contents(result, + self.source) right_offset = offset + 2 if right_offset >= len(target): @@ -933,17 +928,16 @@ self.source[line_index] = ' '.join([left, new_center, right]) def fix_e712(self, result): - """Fix comparison with boolean.""" - line_index = result['line'] - 1 - target = self.source[line_index] - offset = result['column'] - 1 + """Fix (trivial case of) comparison with boolean.""" + (line_index, offset, target) = get_index_offset_contents(result, + self.source) # Handle very easy "not" special cases. - if re.match(r'^\s*if \w+ == False:$', target): - self.source[line_index] = re.sub(r'if (\w+) == False:', + if re.match(r'^\s*if [\w.]+ == False:$', target): + self.source[line_index] = re.sub(r'if ([\w.]+) == False:', r'if not \1:', target, count=1) - elif re.match(r'^\s*if \w+ != True:$', target): - self.source[line_index] = re.sub(r'if (\w+) != True:', + elif re.match(r'^\s*if [\w.]+ != True:$', target): + self.source[line_index] = re.sub(r'if ([\w.]+) != True:', r'if not \1:', target, count=1) else: right_offset = offset + 2 @@ -972,13 +966,13 @@ self.source[line_index] = left + new_right def fix_e713(self, result): - """Fix non-membership check.""" - line_index = result['line'] - 1 - target = self.source[line_index] + """Fix (trivial case of) non-membership check.""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) # Handle very easy case only. - if re.match(r'^\s*if not \w+ in \w+:$', target): - self.source[line_index] = re.sub(r'if not (\w+) in (\w+):', + if re.match(r'^\s*if not [\w.]+ in [\w.]+:$', target): + self.source[line_index] = re.sub(r'if not ([\w.]+) in ([\w.]+):', r'if \1 not in \2:', target, count=1) @@ -988,6 +982,28 @@ fixed_line = self.source[result['line'] - 1].rstrip() self.source[result['line'] - 1] = fixed_line + '\n' + def fix_w391(self, _): + """Remove trailing blank lines.""" + blank_count = 0 + for line in reversed(self.source): + line = line.rstrip() + if line: + break + else: + blank_count += 1 + + original_length = len(self.source) + self.source = self.source[:original_length - blank_count] + return range(1, 1 + original_length) + + +def get_index_offset_contents(result, source): + """Return (line_index, column_offset, line_contents).""" + line_index = result['line'] - 1 + return (line_index, + result['column'] - 1, + source[line_index]) + def get_fixed_long_line(target, previous_line, original, indent_word=' ', max_line_length=79, @@ -1016,17 +1032,28 @@ # Also sort alphabetically as a tie breaker (for determinism). candidates = sorted( sorted(set(candidates).union([target, original])), - key=lambda x: line_shortening_rank(x, - indent_word, - max_line_length, - experimental)) + key=lambda x: line_shortening_rank( + x, + indent_word, + max_line_length, + experimental=experimental)) if verbose >= 4: print(('-' * 79 + '\n').join([''] + candidates + ['']), file=wrap_output(sys.stderr, 'utf-8')) if candidates: - return candidates[0] + best_candidate = candidates[0] + # Don't allow things to get longer. + if longest_line_length(best_candidate) > longest_line_length(original): + return None + else: + return best_candidate + + +def longest_line_length(code): + """Return length of longest line.""" + return max(len(line) for line in code.splitlines()) def join_logical_line(logical_line): @@ -1062,7 +1089,7 @@ last_row = end_row last_column = end_column - return text + return text.rstrip() def _find_logical(source_lines): @@ -2410,9 +2437,12 @@ super(QuietReport, self).__init__(options) self.__full_error_results = [] - def error(self, line_number, offset, text, _): + def error(self, line_number, offset, text, check): """Collect errors.""" - code = super(QuietReport, self).error(line_number, offset, text, _) + code = super(QuietReport, self).error(line_number, + offset, + text, + check) if code: self.__full_error_results.append( {'id': code, @@ -2485,8 +2515,6 @@ return self.input_text # Remove trailing empty lines. lines = self.lines - while lines and lines[-1] == '\n': - lines.pop() # Sentinel. stats.append((len(lines), 0)) # Map count of leading spaces to # we want. @@ -2794,7 +2822,6 @@ # Trim comments that end with things like --------- return line[:max_line_length] + '\n' elif last_comment and re.match(r'\s*#+\s*\w+', line): - import textwrap split_lines = textwrap.wrap(line.lstrip(' \t#'), initial_indent=indentation, subsequent_indent=indentation, @@ -2842,8 +2869,7 @@ "encoding" will be used to decode "source" if it is a byte string. """ - if not options: - options = parse_args([''], apply_config=apply_config) + options = _get_options(options, apply_config) if not isinstance(source, unicode): source = source.decode(encoding or get_encoding()) @@ -2852,6 +2878,30 @@ return fix_lines(sio.readlines(), options=options) +def _get_options(raw_options, apply_config): + """Return parsed options.""" + if not raw_options: + return parse_args([''], apply_config=apply_config) + + if isinstance(raw_options, dict): + options = parse_args([''], apply_config=apply_config) + for name, value in raw_options.items(): + if not hasattr(options, name): + raise ValueError("No such option '{}'".format(name)) + + # Check for very basic type errors. + expected_type = type(getattr(options, name)) + if not isinstance(expected_type, (str, unicode)): + if isinstance(value, (str, unicode)): + raise ValueError( + "Option '{}' should not be a string".format(name)) + setattr(options, name, value) + else: + options = raw_options + + return options + + def fix_lines(source_lines, options, filename=''): """Return fixed source code.""" # Transform everything to line feed. Then change them back to original @@ -2863,7 +2913,8 @@ previous_hashes = set() if options.line_range: - fixed_source = apply_local_fixes(tmp_source, options) + # Disable "apply_local_fixes()" for now due to issue #175. + fixed_source = tmp_source else: # Apply global fixes only once (for efficiency). fixed_source = apply_global_fixes(tmp_source, @@ -2974,194 +3025,6 @@ return source -def apply_local_fixes(source, options): - """Ananologus to apply_global_fixes, but runs only those which makes sense - for the given line_range. - - Do as much as we can without breaking code. - - """ - def find_ge(a, x): - """Find leftmost item greater than or equal to x.""" - i = bisect.bisect_left(a, x) - if i != len(a): - return (i, a[i]) - return (len(a) - 1, a[-1]) - - def find_le(a, x): - """Find rightmost value less than or equal to x.""" - i = bisect.bisect_right(a, x) - if i: - return (i - 1, a[i - 1]) - return (0, a[0]) - - def local_fix(source, start_log, end_log, - start_lines, end_lines, indents, last_line): - """apply_global_fixes to the source between start_log and end_log. - - The subsource must be the correct syntax of a complete python program - (but all lines may share an indentation). The subsource's shared indent - is removed, fixes are applied and the indent prepended back. Taking - care to not reindent strings. - - last_line is the strict cut off (options.line_range[1]), so that - lines after last_line are not modified. - - """ - if end_log < start_log: - return source - - ind = indents[start_log] - indent = _get_indentation(source[start_lines[start_log]]) - - sl = slice(start_lines[start_log], end_lines[end_log] + 1) - - subsource = source[sl] - msl = multiline_string_lines(''.join(subsource), - include_docstrings=False) - # Remove indent from subsource. - if ind: - for line_no in start_lines[start_log:end_log + 1]: - pos = line_no - start_lines[start_log] - subsource[pos] = subsource[pos][ind:] - - # Remove indent from comments. - for (i, line) in enumerate(subsource): - if i + 1 not in msl and re.match(r'\s*#', line): - if line.index('#') >= ind: - subsource[i] = line[ind:] - - # Fix indentation of subsource. - fixed_subsource = apply_global_fixes(''.join(subsource), - options, - where='local') - fixed_subsource = fixed_subsource.splitlines(True) - - # Add back indent for non multi-line strings lines. - msl = multiline_string_lines(''.join(fixed_subsource), - include_docstrings=False) - for (i, line) in enumerate(fixed_subsource): - if not i + 1 in msl: - fixed_subsource[i] = indent + line if line != '\n' else line - - # We make a special case to look at the final line, if it's a multiline - # *and* the cut off is somewhere inside it, we take the fixed - # subset up until last_line, this assumes that the number of lines - # does not change in this multiline line. - changed_lines = len(fixed_subsource) - if ( - start_lines[end_log] != end_lines[end_log] and - end_lines[end_log] > last_line - ): - after_end = end_lines[end_log] - last_line - fixed_subsource = (fixed_subsource[:-after_end] + - source[sl][-after_end:]) - changed_lines -= after_end - - options.line_range[1] = (options.line_range[0] + - changed_lines - 1) - - return (source[:start_lines[start_log]] + - fixed_subsource + - source[end_lines[end_log] + 1:]) - - def is_continued_stmt(line, - continued_stmts=frozenset(['else', 'elif', - 'finally', 'except'])): - return re.split('[ :]', line.strip(), 1)[0] in continued_stmts - - assert options.line_range - (start, end) = options.line_range - start -= 1 - end -= 1 - last_line = end # We shouldn't modify lines after this cut-off. - - try: - logical = _find_logical(source) - except (SyntaxError, tokenize.TokenError): - return ''.join(source) - - if not logical[0]: - # Just blank lines, this should imply that it will become '\n' ? - return apply_global_fixes(source, options) - - (start_lines, indents) = zip(*logical[0]) - (end_lines, _) = zip(*logical[1]) - - source = source.splitlines(True) - - (start_log, start) = find_ge(start_lines, start) - (end_log, end) = find_le(start_lines, end) - - # Look behind one line, if it's indented less than current indent - # then we can move to this previous line knowing that its - # indentation level will not be changed. - if ( - start_log > 0 and - indents[start_log - 1] < indents[start_log] and - not is_continued_stmt(source[start_log - 1]) - ): - start_log -= 1 - start = start_lines[start_log] - - while start < end: - - if is_continued_stmt(source[start]): - start_log += 1 - start = start_lines[start_log] - continue - - ind = indents[start_log] - for t in itertools.takewhile(lambda t: t[1][1] >= ind, - enumerate(logical[0][start_log:])): - (n_log, n) = start_log + t[0], t[1][0] - - # Start shares indent up to n. - if n <= end: - source = local_fix(source, start_log, n_log, - start_lines, end_lines, - indents, last_line) - start_log = n_log if n == end else n_log + 1 - start = start_lines[start_log] - continue - - else: - # Look at the line after end and see if allows us to reindent. - (after_end_log, after_end) = find_ge(start_lines, end + 1) - - if indents[after_end_log] > indents[start_log]: - (start_log, start) = find_ge(start_lines, start + 1) - continue - - if ( - indents[after_end_log] == indents[start_log] and - is_continued_stmt(source[after_end]) - ): - # Find n, the beginning of the last continued statement. - # Apply fix to previous block if there is one. - only_block = True - for n, n_ind in logical[0][start_log:end_log + 1][::-1]: - if n_ind == ind and not is_continued_stmt(source[n]): - n_log = start_lines.index(n) - source = local_fix(source, start_log, n_log - 1, - start_lines, end_lines, - indents, last_line) - start_log = n_log + 1 - start = start_lines[start_log] - only_block = False - break - if only_block: - (end_log, end) = find_le(start_lines, end - 1) - continue - - source = local_fix(source, start_log, end_log, - start_lines, end_lines, - indents, last_line) - break - - return ''.join(source) - - def extract_code_from_function(function): """Return code handled by function.""" if not function.__name__.startswith('fix_'): @@ -3189,11 +3052,11 @@ prog='autopep8') parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) - parser.add_argument('-v', '--verbose', action='count', dest='verbose', + parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose messages; ' 'multiple -v result in more verbose messages') - parser.add_argument('-d', '--diff', action='store_true', dest='diff', + parser.add_argument('-d', '--diff', action='store_true', help='print the diff for the fixed source') parser.add_argument('-i', '--in-place', action='store_true', help='make changes to files in place') @@ -3235,7 +3098,7 @@ parser.add_argument('--max-line-length', metavar='n', default=79, type=int, help='set maximum allowed line length ' '(default: %(default)s)') - parser.add_argument('--range', metavar='line', dest='line_range', + parser.add_argument('--line-range', '--range', metavar='line', default=None, type=int, nargs=2, help='only fix errors found within this inclusive ' 'range of line numbers (e.g. 1 99); ' @@ -3286,9 +3149,6 @@ if args.recursive and not (args.in_place or args.diff): parser.error('--recursive must be used with --in-place or --diff') - if args.exclude and not args.recursive: - parser.error('--exclude is only relevant when used with --recursive') - if args.in_place and args.diff: parser.error('--in-place and --diff are mutually exclusive') @@ -3366,7 +3226,7 @@ def _split_comma_separated(string): """Return a set of strings.""" - return set(filter(None, string.split(','))) + return set(text.strip() for text in string.split(',') if text.strip()) def decode_filename(filename): @@ -3421,7 +3281,7 @@ return 0 rank = 0 - lines = candidate.split('\n') + lines = candidate.rstrip().split('\n') offset = 0 if ( @@ -3472,6 +3332,12 @@ if current_line == bad_start: rank += 1000 + if ( + current_line.endswith(('.', '%', '+', '-', '/')) and + "': " in current_line + ): + rank += 1000 + if current_line.endswith(('(', '[', '{', '.')): # Avoid lonely opening. They result in longer lines. if len(current_line) <= len(indent_word): @@ -3491,6 +3357,13 @@ if has_arithmetic_operator(current_line): rank += 100 + # Avoid breaking at unary operators. + if re.match(r'.*[(\[{]\s*[\-\+~]$', current_line.rstrip('\\ ')): + rank += 1000 + + if re.match(r'.*lambda\s*\*$', current_line.rstrip('\\ ')): + rank += 1000 + if current_line.endswith(('%', '(', '[', '{')): rank -= 20 @@ -3528,6 +3401,10 @@ if ',' in current_line and current_line.endswith(':'): rank += 10 + # Avoid splitting dictionaries between key and value. + if current_line.endswith(':'): + rank += 100 + rank += 10 * count_unbalanced_brackets(current_line) return max(0, rank) @@ -3705,8 +3582,11 @@ return locale.getpreferredencoding() or sys.getdefaultencoding() -def main(apply_config=True): - """Tool main.""" +def main(argv=None, apply_config=True): + """Command-line entry.""" + if argv is None: + argv = sys.argv + try: # Exit on broken pipe. signal.signal(signal.SIGPIPE, signal.SIG_DFL) @@ -3715,7 +3595,7 @@ pass try: - args = parse_args(sys.argv[1:], apply_config=apply_config) + args = parse_args(argv[1:], apply_config=apply_config) if args.list_fixes: for code, description in sorted(supported_fixes()): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/setup.cfg new/autopep8-1.2/setup.cfg --- old/autopep8-1.1.1/setup.cfg 2015-02-26 06:58:32.000000000 +0100 +++ new/autopep8-1.2/setup.cfg 2015-07-27 06:41:08.000000000 +0200 @@ -1,6 +1,3 @@ -[bdist_wheel] -universal = 1 - [egg_info] tag_build = tag_date = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.1.1/test/test_autopep8.py new/autopep8-1.2/test/test_autopep8.py --- old/autopep8-1.1.1/test/test_autopep8.py 2015-02-26 06:38:55.000000000 +0100 +++ new/autopep8-1.2/test/test_autopep8.py 2015-06-03 06:01:19.000000000 +0200 @@ -312,6 +312,26 @@ 'print(123)\n', autopep8.fix_code(b'print( 123 )\n')) + def test_fix_code_with_options(self): + self.assertEqual( + 'print(123)\n', + autopep8.fix_code('print( 123 )\n', options={'ignore': ['W']})) + + self.assertEqual( + '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']}) + + with self.assertRaises(ValueError): + autopep8.fix_code('print( 123 )\n', options={'ignore': 'W'}) + def test_normalize_line_endings(self): self.assertEqual( ['abc\n', 'def\n', '123\n', 'hello\n', 'world\n'], @@ -2080,7 +2100,6 @@ ''' fixed = '''\ class Foo(object): - """Test.""" def foo(self): @@ -2226,6 +2245,20 @@ with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e501_with_dictionary(self): + line = """\ +myDict = { 'kg': 1, 'tonnes': tonne, 't/y': tonne / year, 'Mt/y': 1e6 * tonne / year} +""" + fixed = """\ +myDict = { + 'kg': 1, + 'tonnes': tonne, + 't/y': tonne / year, + 'Mt/y': 1e6 * tonne / year} +""" + with autopep8_context(line, options=['--aggressive']) as result: + self.assertEqual(fixed, result) + def test_e501_with_in(self): line = """\ if True: @@ -2340,8 +2373,8 @@ """ fixed = """\ if True: - reconstructed = iradon( - radon(image), filter="ramp", interpolation="nearest") + reconstructed = iradon(radon(image), filter="ramp", + interpolation="nearest") """ with autopep8_context(line) as result: self.assertEqual(fixed, result) @@ -2371,6 +2404,36 @@ with autopep8_context(line, options=['--aggressive']) as result: self.assertEqual(fixed, result) + def test_e501_with_lambda(self): + line = """\ +self.mock_group.modify_state.side_effect = lambda *_: defer.fail(NoSuchScalingGroupError(1, 2)) +""" + fixed = """\ +self.mock_group.modify_state.side_effect = lambda *_: defer.fail( + NoSuchScalingGroupError(1, 2)) +""" + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + + def test_e501_shorten_with_backslash(self): + line = """\ +class Bar(object): + + def bar(self, position): + if 0 <= position <= self._blocks[-1].position + len(self._blocks[-1].text): + pass +""" + fixed = """\ +class Bar(object): + + def bar(self, position): + if 0 <= position <= self._blocks[-1].position + \\ + len(self._blocks[-1].text): + pass +""" + with autopep8_context(line, options=['--aggressive']) as result: + self.assertEqual(fixed, result) + def test_e501_shorten_at_commas_skip(self): line = """\ parser.add_argument('source_corpus', help='corpus name/path relative to an nltk_data directory') @@ -2495,20 +2558,6 @@ with autopep8_context(line) as result: self.assertEqual(line, result) - def test_e501_prefer_to_break_at_begnning(self): - """We prefer not to leave part of the arguments hanging.""" - line = """\ - -looooooooooooooong = foo(one, two, three, four, five, six, seven, eight, nine, ten) -""" - fixed = """\ - -looooooooooooooong = foo( - one, two, three, four, five, six, seven, eight, nine, ten) -""" - with autopep8_context(line) as result: - self.assertEqual(fixed, result) - def test_e501_avoid_breaking_at_empty_parentheses_if_possible(self): line = """\ someverylongindenttionwhatnot().foo().bar().baz("and here is a long string 123456789012345678901234567890") @@ -3090,8 +3139,8 @@ pass """ fixed = """\ -# test test test test test test test test test test test test test test -if True or False: +if True or \\ + False: # test test test test test test test test test test test test test test pass """ with autopep8_context(line, options=['-aa']) as result: @@ -3176,10 +3225,9 @@ fixed = """\ if True: # comment here - print( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, - cccccccccccccccccccccccccccccccccccccccccc) + print(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccccccccccccc) """ with autopep8_context(line, options=['-aa']) as result: self.assertEqual(fixed, result) @@ -3277,8 +3325,7 @@ def f(): man_this_is_a_very_long_function_name( an_extremely_long_variable_name, - ('a string that is long: %s' % - 'bork')) + ('a string that is long: %s' % 'bork')) """ with autopep8_context(line, options=['-aa']) as result: self.assertEqual(fixed, result) @@ -3291,9 +3338,8 @@ """ fixed = """\ def f(self): - self._xxxxxxxx( - aaaaaa, bbbbbbbbb, cccccccccccccccccc, [ - ('mmmmmmmmmm', self.yyyyyyyyyy.zzzzzzz / _DDDDD)], eee, 'ff') + self._xxxxxxxx(aaaaaa, bbbbbbbbb, cccccccccccccccccc, [ + ('mmmmmmmmmm', self.yyyyyyyyyy.zzzzzzz / _DDDDD)], eee, 'ff') """ with autopep8_context(line, options=['-aa']) as result: @@ -3304,15 +3350,8 @@ @foo(('xxxxxxxxxxxxxxxxxxxxxxxxxx', users.xxxxxxxxxxxxxxxxxxxxxxxxxx), ('yyyyyyyyyyyy', users.yyyyyyyyyyyy), ('zzzzzzzzzzzzzz', users.zzzzzzzzzzzzzz)) """ fixed = """\ - - -@foo( - ('xxxxxxxxxxxxxxxxxxxxxxxxxx', - users.xxxxxxxxxxxxxxxxxxxxxxxxxx), - ('yyyyyyyyyyyy', - users.yyyyyyyyyyyy), - ('zzzzzzzzzzzzzz', - users.zzzzzzzzzzzzzz)) +@foo(('xxxxxxxxxxxxxxxxxxxxxxxxxx', users.xxxxxxxxxxxxxxxxxxxxxxxxxx), + ('yyyyyyyyyyyy', users.yyyyyyyyyyyy), ('zzzzzzzzzzzzzz', users.zzzzzzzzzzzzzz)) """ with autopep8_context(line, options=['-aa']) as result: @@ -4063,167 +4102,41 @@ def test_range(self): line = 'print( 1 )\nprint( 2 )\n print( 3 )\n' fixed = 'print( 1 )\nprint(2)\n print( 3 )\n' - with autopep8_context(line, options=['--range', '2', '2']) as result: + with autopep8_context(line, options=['--line-range', '2', '2']) as result: self.assertEqual(fixed, result) def test_range_line_number_changes_from_one_line(self): line = 'a=12\na=1; b=2;c=3\nd=4;\n\ndef f(a = 1):\n pass\n' fixed = 'a=12\na = 1\nb = 2\nc = 3\nd=4;\n\ndef f(a = 1):\n pass\n' - with autopep8_context(line, options=['--range', '2', '2']) as result: + with autopep8_context(line, options=['--line-range', '2', '2']) as result: self.assertEqual(fixed, result) - def test_range_indent_changes_large_range(self): - line = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - fixed0_9 = '\nif True:\n (1,\n 2,\n 3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - with autopep8_context(line, options=['--range', '1', '9']) as result: - self.assertEqual(fixed0_9, result) - def test_range_indent_changes_small_range(self): line = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' fixed2_5 = '\nif True:\n (1,\n 2,\n 3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - with autopep8_context(line, options=['--range', '2', '5']) as result: + with autopep8_context(line, options=['--line-range', '2', '5']) as result: self.assertEqual(fixed2_5, result) - def test_range_indent_changes_multiline(self): - line = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - fixed_11_15 = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n 2)\n' - with autopep8_context(line, options=['--range', '11', '15']) as result: - self.assertEqual(fixed_11_15, result) - - def test_range_indent_changes_partial_multiline(self): - line = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - fixed_11_14 = '\nif True:\n (1, \n 2,\n3)\nelif False:\n a = 1\nelse:\n a = 2\n\nc = 1\nif True:\n c = 2\n a = (1,\n2)\n' - with autopep8_context(line, options=['--range', '11', '14']) as result: - self.assertEqual(fixed_11_14, result) - - def test_range_indent_long_multiline_small_range(self): - line = '\nif True:\n (1,\n2,\n3,\n\n4,\n\n5,\n6)' - fixed_2_3 = '\nif True:\n (1,\n2,\n3,\n\n4,\n\n5,\n6)\n' - with autopep8_context(line, options=['--range', '2', '3']) as result: - self.assertEqual(fixed_2_3, result) - - def test_range_indent_long_multiline_partial_range(self): - line = '\nif True:\n (1,\n2,\n3,\n\n4,\n\n5,\n6)' - fixed_2_6 = '\nif True:\n (1,\n 2,\n 3,\n\n4,\n\n5,\n6)\n' - with autopep8_context(line, options=['--range', '2', '6']) as result: - self.assertEqual(fixed_2_6, result) - - def test_range_indent_long_multiline_middle_of_multiline(self): - line = '\nif True:\n (1,\n2,\n3,\n\n4,\n\n5,\n6)' - # weird-ish edge case, fixes earlier lines (up to beginning of - # multi-line block) - fixed_2_6 = '\nif True:\n (1,\n 2,\n 3,\n\n 4,\n\n5,\n6)\n' - with autopep8_context(line, options=['--range', '4', '6']) as result: - self.assertEqual(fixed_2_6, result) - def test_range_indent_deep_if_blocks_first_block(self): line = '\nif a:\n if a = 1:\n b = 1\n else:\n b = 2\nelif a == 0:\n b = 3\nelse:\n b = 4\n' - with autopep8_context(line, options=['--range', '2', '5']) as result: + with autopep8_context(line, options=['--line-range', '2', '5']) as result: self.assertEqual(line, result) - def test_range_indent_deep_if_blocks_large_range(self): - line = '\nif a:\n if a = 1:\n b = 1\n else:\n b = 2\nelif a == 0:\n b = 3\nelse:\n b = 4\n' - fixed_2_7 = '\nif a:\n if a = 1:\n b = 1\n else:\n b = 2\nelif a == 0:\n b = 3\nelse:\n b = 4\n' - with autopep8_context(line, options=['--range', '2', '7']) as result: - self.assertEqual(fixed_2_7, result) - def test_range_indent_deep_if_blocks_second_block(self): line = '\nif a:\n if a = 1:\n b = 1\n else:\n b = 2\nelif a == 0:\n b = 3\nelse:\n b = 4\n' - with autopep8_context(line, options=['--range', '6', '9']) as result: + with autopep8_context(line, options=['--line-range', '6', '9']) as result: self.assertEqual(line, result) - def test_range_indent_continued_statements(self): - line = '\nif a == 1:\n\ttry:\n\t foo\n\texcept AttributeError:\n\t pass\n\telse:\n\t "nooo"\n\tb = 1\n' - fixed_2_8 = '\nif a == 1:\n\ttry:\n\t foo\n\texcept AttributeError:\n\t pass\n\telse:\n\t "nooo"\n\tb = 1\n' - with autopep8_context(line, options=['--range', '2', '8']) as result: - self.assertEqual(fixed_2_8, result) - def test_range_indent_continued_statements_partial(self): line = '\nif a == 1:\n\ttry:\n\t foo\n\texcept AttributeError:\n\t pass\n\telse:\n\t "nooo"\n\tb = 1\n' - with autopep8_context(line, options=['--range', '2', '6']) as result: + with autopep8_context(line, options=['--line-range', '2', '6']) as result: self.assertEqual(line, result) def test_range_indent_continued_statements_last_block(self): line = '\nif a == 1:\n\ttry:\n\t foo\n\texcept AttributeError:\n\t pass\n\telse:\n\t "nooo"\n\tb = 1\n' - with autopep8_context(line, options=['--range', '6', '9']) as result: + with autopep8_context(line, options=['--line-range', '6', '9']) as result: self.assertEqual(line, result) - def test_range_indent_neighbouring_blocks(self): - line = '\nif a == 1:\n b = 1\nif a == 2:\n b = 2\nif a == 3:\n b = 3\n' - fixed_2_3 = '\nif a == 1:\n b = 1\nif a == 2:\n b = 2\nif a == 3:\n b = 3\n' - with autopep8_context(line, options=['--range', '2', '3']) as result: - self.assertEqual(fixed_2_3, result) - - def test_range_indent_neighbouring_blocks_one_line(self): - line = '\nif a == 1:\n b = 1\nif a == 2:\n b = 2\nif a == 3:\n b = 3\n' - fixed_2_3 = '\nif a == 1:\n b = 1\nif a == 2:\n b = 2\nif a == 3:\n b = 3\n' - fixed_3_3 = fixed_2_3 - with autopep8_context(line, options=['--range', '3', '3']) as result: - self.assertEqual(fixed_3_3, result) - - def test_range_indent_above_less_indented(self): - line = '\ndef f(x):\n if x:\n return x\n' - fixed_3_4 = '\ndef f(x):\n if x:\n return x\n' - with autopep8_context(line, options=['--range', '3', '4']) as result: - self.assertEqual(fixed_3_4, result) - - def test_range_indent_docstrings_partial(self): - line = '\ndef f(x):\n """docstring\n docstring"""\n #comment\n if x:\n return x\n' - # TODO this should fix the comment spacing - fixed_2_5 = '\ndef f(x):\n """docstring\n docstring"""\n #comment\n if x:\n return x\n' - with autopep8_context(line, options=['--range', '2', '5']) as result: - self.assertEqual(fixed_2_5, result) - - def test_range_indent_docstrings(self): - line = '\ndef f(x):\n """docstring\n docstring"""\n #comment\n if x:\n return x\n' - fixed_2_7 = '\ndef f(x):\n """docstring\n docstring"""\n # comment\n if x:\n return x\n' - with autopep8_context(line, options=['--range', '2', '7']) as result: - self.assertEqual(fixed_2_7, result) - - def test_range_indent_multiline_strings(self): - line = '\nif True:\n a = """multi\nline\nstring"""\n #comment\n a=1\na=2\n' - fixed_2_7 = '\nif True:\n a = """multi\nline\nstring"""\n # comment\n a = 1\na=2\n' - with autopep8_context(line, options=['--range', '2', '7']) as result: - self.assertEqual(fixed_2_7, result) - - def test_range_indent_multiline_strings_and_docstring(self): - code_ = ''' -def f(): - """docstring - continued""" - a = """multi -line -string""" - #comment - a=1 -a=2 -''' - fixed_2_7 = ''' -def f(): - """docstring - continued""" - a = """multi -line -string""" - # comment - a = 1 -a=2 -''' - with autopep8_context(code_, options=['--range', '2', '9']) as result: - self.assertEqual(fixed_2_7, result) - - def test_range_with_indented_comments(self): - code_ = 'if True:\n if True:\n if True:\n # bah\n pass\n' - fixed = 'if True:\n if True:\n if True:\n # bah\n pass\n' - with autopep8_context(code_, options=['--range', '4', '5']) as result: - self.assertEqual(fixed, result) - - def test_range_with_indented_comments_spaced(self): - code_ = 'if True:\n if True:\n if True:\n # bah\n\n pass\n' - fixed = 'if True:\n if True:\n if True:\n # bah\n\n pass\n' - with autopep8_context(code_, options=['--range', '4', '6']) as result: - self.assertEqual(fixed, result) - def test_range_with_broken_syntax(self): line = """\ if True: @@ -4232,7 +4145,7 @@ else: pass """ - with autopep8_context(line, options=['--range', '1', '1']) as result: + with autopep8_context(line, options=['--line-range', '1', '1']) as result: self.assertEqual(line, result) @@ -4452,15 +4365,14 @@ with temporary_file_context(line) as filename: for options in [['--recursive', filename], # without --diff ['--jobs=2', filename], # without --diff - ['--exclude=foo', filename], # without --recursive ['--max-line-length=0', filename], [], # no argument ['-', '--in-place'], ['-', '--recursive'], ['-', filename], - ['--range', '0', '2', filename], - ['--range', '2', '1', filename], - ['--range', '-1', '-1', filename], + ['--line-range', '0', '2', filename], + ['--line-range', '2', '1', filename], + ['--line-range', '-1', '-1', filename], ]: p = Popen(list(AUTOPEP8_CMD_TUPLE) + options, stderr=PIPE) @@ -4600,9 +4512,8 @@ print(111, 111, 111, 111, 222, 222, 222, 222, 222, 222, 222, 222, 222, 333, 333, 333, 333) """ fixed = """\ -print( - 111, 111, 111, 111, 222, 222, 222, 222, 222, 222, 222, 222, 222, 333, 333, - 333, 333) +print(111, 111, 111, 111, 222, 222, 222, 222, + 222, 222, 222, 222, 222, 333, 333, 333, 333) """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -4612,9 +4523,8 @@ foobar = {'aaaaaaaaaaaa': 'bbbbbbbbbbbbbbbb', 'dddddd': 'eeeeeeeeeeeeeeee', 'ffffffffffff': 'gggggggg'} """ fixed = """\ -foobar = { - 'aaaaaaaaaaaa': 'bbbbbbbbbbbbbbbb', 'dddddd': 'eeeeeeeeeeeeeeee', - 'ffffffffffff': 'gggggggg'} +foobar = {'aaaaaaaaaaaa': 'bbbbbbbbbbbbbbbb', + 'dddddd': 'eeeeeeeeeeeeeeee', 'ffffffffffff': 'gggggggg'} """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -4714,10 +4624,8 @@ x = [3244234243234, 234234234324, 234234324, 23424234, 234234234, 234234, 234243, 234243, 234234234324, 234234324, 23424234, 234234234, 234234, 234243, 234243] """ fixed = """\ -x = [ - 3244234243234, 234234234324, 234234324, 23424234, 234234234, 234234, - 234243, 234243, 234234234324, 234234324, 23424234, 234234234, 234234, - 234243, 234243] +x = [3244234243234, 234234234324, 234234324, 23424234, 234234234, 234234, 234243, + 234243, 234234234324, 234234324, 23424234, 234234234, 234234, 234243, 234243] """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -4760,9 +4668,8 @@ fixed = """\ def d(): - print( - 111, 111, 111, 111, 222, 222, 222, 222, 222, 222, 222, 222, 222, 333, - 333, 333, 333) + print(111, 111, 111, 111, 222, 222, 222, 222, + 222, 222, 222, 222, 222, 333, 333, 333, 333) """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -4774,14 +4681,14 @@ """ fixed = """\ if True: - print( - 111, 111, 111, 111, 222, 222, 222, 222, 222, 222, 222, 222, 222, 333, - 333, 333, 333) + print(111, 111, 111, 111, 222, 222, 222, 222, + 222, 222, 222, 222, 222, 333, 333, 333, 333) """ with autopep8_context(line, options=['--select=E501', '--experimental']) as result: self.assertEqual(fixed, result) + @unittest.skip('Not sure why space is not removed anymore') def test_e501_experimental_alone_with_tuple(self): line = """\ fooooooooooooooooooooooooooooooo000000000000000000000000 = [1, @@ -4803,9 +4710,8 @@ this_should_be_shortened = (' ', ' ') """ fixed = """\ -term3 = w6 * c5 * ( - 8.0 * psi4 * (11.0 - 24.0 * t2) - 28 * psi3 * (1 - 6.0 * t2) + psi2 * - (1 - 32 * t2) - psi * (2.0 * t2) + t4) / 720.0 +term3 = w6 * c5 * (8.0 * psi4 * (11.0 - 24.0 * t2) - 28 * psi3 * (1 - 6.0 * t2) + + psi2 * (1 - 32 * t2) - psi * (2.0 * t2) + t4) / 720.0 this_should_be_shortened = ( ' ', ' ') @@ -4857,18 +4763,6 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) - def test_e501_experimental_prefer_to_break_at_beginning(self): - """We prefer not to leave part of the arguments hanging.""" - line = """\ -looooooooooooooong = foo(one, two, three, four, five, six, seven, eight, nine, ten) -""" - fixed = """\ -looooooooooooooong = foo( - one, two, three, four, five, six, seven, eight, nine, ten) -""" - with autopep8_context(line, options=['--experimental']) as result: - self.assertEqual(fixed, result) - def test_e501_experimental_with_logical_fix(self): line = """\ xxxxxxxxxxxxxxxxxxxxxxxxxxxx(aaaaaaaaaaaaaaaaaaaaaaa, @@ -5101,7 +4995,6 @@ self.assertEqual(fixed, result) def test_e501_with_experimental(self): - # FIXME: This has really bad output. line = """\ models = { 'auth.group': { @@ -5114,27 +5007,8 @@ }, } """ - fixed = """\ -models = { - 'auth.group': - {'Meta': {'object_name': 'Group'}, - 'permissions': - ('django.db.models.fields.related.ManyToManyField', [], - {'to': "orm['auth.Permission']", 'symmetrical': 'False', - 'blank': 'True'})}, - 'auth.permission': - { - 'Meta': - { - 'ordering': - "('content_type__app_label', 'content_type__model', 'codename')", - 'unique_together': "(('content_type', 'codename'),)", - 'object_name': 'Permission'}, - 'name': ('django.db.models.fields.CharField', [], - {'max_length': '50'})}, } -""" with autopep8_context(line, options=['--experimental']) as result: - self.assertEqual(fixed, result) + self.assertEqual(line, result) def test_e501_experimental_and_multiple_logical_lines(self): line = """\ @@ -5197,8 +5071,8 @@ pass """ fixed = """\ -# test test test test test test test test test test test test test test -if True or False: +if True or \\ + False: # test test test test test test test test test test test test test test pass """ with autopep8_context(line, options=['--experimental']) as result: @@ -5277,10 +5151,9 @@ fixed = """\ if True: # comment here - print( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, - cccccccccccccccccccccccccccccccccccccccccc) + print(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccccccccccccc) """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -5338,11 +5211,8 @@ pass """ fixed = """\ - - -def foobar( - sldfkjlsdfsdf, kksdfsdfsf, sdfsdfsdf, sdfsdfkdk, szdfsdfsdf, - sdfsdfsdfsdlkfjsdlf, sdfsdfddf, sdfsdfsfd, sdfsdfdsf): +def foobar(sldfkjlsdfsdf, kksdfsdfsf, sdfsdfsdf, sdfsdfkdk, szdfsdfsdf, + sdfsdfsdfsdlkfjsdlf, sdfsdfddf, sdfsdfsfd, sdfsdfdsf): pass """ with autopep8_context(line, options=['--experimental']) as result: @@ -5399,22 +5269,6 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) - def test_e501_experimental_with_multiple_lines_and_quotes(self): - line = """\ -if True: - xxxxxxxxxxx = xxxxxxxxxxxxxxxxx(xxxxxxxxxxx, xxxxxxxxxxxxxxxx={'xxxxxxxxxxxx': 'xxxxx', - 'xxxxxxxxxxx': xx, - 'xxxxxxxx': False, - }) -""" - fixed = """\ -if True: - xxxxxxxxxxx = xxxxxxxxxxxxxxxxx( - xxxxxxxxxxx, - xxxxxxxxxxxxxxxx={'xxxxxxxxxxxx': 'xxxxx', 'xxxxxxxxxxx': xx, - 'xxxxxxxx': False, }) -""" - with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) @@ -5473,6 +5327,7 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) + @unittest.skip('To do') def test_e501_experimental_tuple_on_line(self): line = """\ def f(): @@ -5528,10 +5383,9 @@ fixed = """\ -@foo( - ('xxxxxxxxxxxxxxxxxxxxxxxxxx', users.xxxxxxxxxxxxxxxxxxxxxxxxxx), - ('yyyyyyyyyyyy', users.yyyyyyyyyyyy), - ('zzzzzzzzzzzzzz', users.zzzzzzzzzzzzzz)) +@foo(('xxxxxxxxxxxxxxxxxxxxxxxxxx', users.xxxxxxxxxxxxxxxxxxxxxxxxxx), + ('yyyyyyyyyyyy', users.yyyyyyyyyyyy), + ('zzzzzzzzzzzzzz', users.zzzzzzzzzzzzzz)) """ with autopep8_context(line, options=['--experimental']) as result:
participants (1)
-
root@hilbert.suse.de