Revised formatting to work with multiple implicitly concatenated strings
This commit is contained in:
parent
5c8d6a8bb4
commit
1ef76f3a0a
|
@ -344,18 +344,19 @@ def _compare_eq_iterable(
|
|||
|
||||
if _is_empty_vs_non_empty(left, right):
|
||||
left_formatting, right_formatting = _format_for_empty_and_non_empty(left, right)
|
||||
lines_left = len(left_formatting)
|
||||
lines_right = len(right_formatting)
|
||||
else:
|
||||
left_formatting = pprint.pformat(left).splitlines()
|
||||
right_formatting = pprint.pformat(right).splitlines()
|
||||
|
||||
# Re-format for different output lengths.
|
||||
lines_left = len(left_formatting)
|
||||
lines_right = len(right_formatting)
|
||||
lines_left = len(left_formatting)
|
||||
lines_right = len(right_formatting)
|
||||
|
||||
if lines_left != lines_right:
|
||||
printer = PrettyPrinter()
|
||||
left_formatting = printer.pformat(left).splitlines()
|
||||
right_formatting = printer.pformat(right).splitlines()
|
||||
if lines_left != lines_right:
|
||||
printer = PrettyPrinter()
|
||||
left_formatting = printer.pformat(left).splitlines()
|
||||
right_formatting = printer.pformat(right).splitlines()
|
||||
|
||||
if lines_left > 1 or lines_right > 1:
|
||||
_surrounding_parens_on_own_lines(left_formatting)
|
||||
|
@ -389,16 +390,15 @@ def _format_for_empty_and_non_empty(
|
|||
) -> Tuple[List[str], List[str]]:
|
||||
if isinstance(left, (list, tuple)) and isinstance(right, (list, tuple)):
|
||||
if not left:
|
||||
right_width = len(right[0]) + 4 if right else 80
|
||||
right_width = max(len(s) + 4 for s in right)
|
||||
right_formatting = pprint.pformat(right, width=right_width).splitlines()
|
||||
left_formatting = pprint.pformat(left).splitlines()
|
||||
else:
|
||||
left_width = len(left[0]) + 4 if left else 80
|
||||
left_width = max(len(s) + 4 for s in left)
|
||||
left_formatting = pprint.pformat(left, width=left_width).splitlines()
|
||||
right_formatting = pprint.pformat(right).splitlines()
|
||||
return left_formatting, right_formatting
|
||||
else:
|
||||
# Fall back to default formatting
|
||||
return pprint.pformat(left).splitlines(), pprint.pformat(right).splitlines()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue