Skip to content

Commit

Permalink
Avoid growing the line length
Browse files Browse the repository at this point in the history
This fixes #141.
  • Loading branch information
myint committed Mar 27, 2015
1 parent ffab2c8 commit fe3737c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,17 +1013,28 @@ def get_fixed_long_line(target, previous_line, original,
# 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):
Expand Down

0 comments on commit fe3737c

Please sign in to comment.