Skip to content

Commit f0a5df6

Browse files
committed
apply pre_commit hooks (black)
1 parent 5a579fc commit f0a5df6

4 files changed

Lines changed: 40 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ format:
503503
>>> print(tabulate(table, headers, tablefmt="asciidoc"))
504504
[cols="8<,7>",options="header"]
505505
|====
506-
| item | qty
507-
| spam | 42
508-
| eggs | 451
509-
| bacon | 0
506+
| item | qty
507+
| spam | 42
508+
| eggs | 451
509+
| bacon | 0
510510
|====
511511

512512
```
@@ -1065,11 +1065,11 @@ the lines being wrapped would probably be significantly longer than this.
10651065

10661066
Text is preferably wrapped on whitespaces and right after the hyphens in hyphenated words.
10671067

1068-
break_long_words (default: True) If true, then words longer than width will be broken in order to ensure that no lines are longer than width.
1068+
break_long_words (default: True) If true, then words longer than width will be broken in order to ensure that no lines are longer than width.
10691069
If it is false, long words will not be broken, and some lines may be longer than width.
10701070
(Long words will be put on a line by themselves, in order to minimize the amount by which width is exceeded.)
10711071

1072-
break_on_hyphens (default: True) If true, wrapping will occur preferably on whitespaces and right after hyphens in compound words, as it is customary in English.
1072+
break_on_hyphens (default: True) If true, wrapping will occur preferably on whitespaces and right after hyphens in compound words, as it is customary in English.
10731073
If false, only whitespaces will be considered as potentially good places for line breaks.
10741074

10751075
```pycon

tabulate/__init__.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,14 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
16381638
return rows, headers, headers_pad
16391639

16401640

1641-
def _wrap_text_to_colwidths(list_of_lists, colwidths, numparses=True, missingval=_DEFAULT_MISSINGVAL, break_long_words=_BREAK_LONG_WORDS, break_on_hyphens=_BREAK_ON_HYPHENS):
1641+
def _wrap_text_to_colwidths(
1642+
list_of_lists,
1643+
colwidths,
1644+
numparses=True,
1645+
missingval=_DEFAULT_MISSINGVAL,
1646+
break_long_words=_BREAK_LONG_WORDS,
1647+
break_on_hyphens=_BREAK_ON_HYPHENS,
1648+
):
16421649
if len(list_of_lists):
16431650
num_cols = len(list_of_lists[0])
16441651
else:
@@ -1655,13 +1662,21 @@ def _wrap_text_to_colwidths(list_of_lists, colwidths, numparses=True, missingval
16551662
continue
16561663

16571664
if width is not None:
1658-
wrapper = _CustomTextWrap(width=width, break_long_words=break_long_words, break_on_hyphens=break_on_hyphens)
1665+
wrapper = _CustomTextWrap(
1666+
width=width,
1667+
break_long_words=break_long_words,
1668+
break_on_hyphens=break_on_hyphens,
1669+
)
16591670
# Cast based on our internal type handling. Any future custom
16601671
# formatting of types (such as datetimes) may need to be more
16611672
# explicit than just `str` of the object. Also doesn't work for
16621673
# custom floatfmt/intfmt, nor with any missing/blank cells.
16631674
casted_cell = (
1664-
missingval if cell is None else str(cell) if cell == '' or _isnumber(cell) else str(_type(cell, numparse)(cell))
1675+
missingval
1676+
if cell is None
1677+
else str(cell)
1678+
if cell == "" or _isnumber(cell)
1679+
else str(_type(cell, numparse)(cell))
16651680
)
16661681
wrapped = [
16671682
"\n".join(wrapper.wrap(line))
@@ -2264,7 +2279,12 @@ def tabulate(
22642279

22652280
numparses = _expand_numparse(disable_numparse, num_cols)
22662281
list_of_lists = _wrap_text_to_colwidths(
2267-
list_of_lists, maxcolwidths, numparses=numparses, missingval=missingval, break_long_words=break_long_words, break_on_hyphens=break_on_hyphens
2282+
list_of_lists,
2283+
maxcolwidths,
2284+
numparses=numparses,
2285+
missingval=missingval,
2286+
break_long_words=break_long_words,
2287+
break_on_hyphens=break_on_hyphens,
22682288
)
22692289

22702290
if maxheadercolwidths is not None:
@@ -2278,7 +2298,12 @@ def tabulate(
22782298

22792299
numparses = _expand_numparse(disable_numparse, num_cols)
22802300
headers = _wrap_text_to_colwidths(
2281-
[headers], maxheadercolwidths, numparses=numparses, missingval=missingval, break_long_words=break_long_words, break_on_hyphens=break_on_hyphens
2301+
[headers],
2302+
maxheadercolwidths,
2303+
numparses=numparses,
2304+
missingval=missingval,
2305+
break_long_words=break_long_words,
2306+
break_on_hyphens=break_on_hyphens,
22822307
)[0]
22832308

22842309
# empty values in the first column of RST tables should be escaped (issue #82)

test/test_output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,7 @@ def test_preserve_whitespace():
33203320
result = tabulate(test_table, table_headers, preserve_whitespace=False)
33213321
assert_equal(expected, result)
33223322

3323+
33233324
def test_break_long_words():
33243325
"Output: Default table output, with breakwords true."
33253326
table_headers = ["h1", "h2", "h3"]
@@ -3335,6 +3336,7 @@ def test_break_long_words():
33353336
result = tabulate(test_table, table_headers, maxcolwidths=3, break_long_words=True)
33363337
assert_equal(expected, result)
33373338

3339+
33383340
def test_break_on_hyphens():
33393341
"Output: Default table output, with break on hyphens true."
33403342
table_headers = ["h1", "h2", "h3"]

test/test_textwrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def test_wrap_none_value_with_missingval():
263263
"+---------+---------+",
264264
]
265265
expected = "\n".join(expected)
266-
assert_equal(expected, result)
266+
assert_equal(expected, result)
267+
267268

268-
269269
def test_wrap_optional_bool_strs():
270270
"""TextWrapper: Show that str bools and None can be wrapped without crashing"""
271271
data = [

0 commit comments

Comments
 (0)