Repository: astanin/python-tabulate

Issue:
Custom TableFormat gives: TypeError: unhashable type: 'list'
Cloned tabulate from master (433dfc69f2abba1c463763d33e1fb3bcdd3afe37) and tried to use custom TableFormat:

Script:

```
from tabulate import tabulate, TableFormat, Line, DataRow

tablefmt = TableFormat(
        lineabove        = Line("", "-", "  ", ""),
        linebelowheader  = Line("", "-", "  ", ""),
        linebetweenrows  = None,
        linebelow        = Line("", "-", "  ", ""),
        headerrow        = DataRow("", "  ", ""),
        datarow          = DataRow("", "  ", ""),
        padding          = 0,
        with_header_hide = ["lineabove", "linebelow"])

rows = [
    ['foo', 'bar'],
    ['baz', 'qux'] ]

print(tabulate(rows, headers=['A', 'B'], tablefmt=tablefmt))
```

Output:

```
Traceback (most recent call last):
  File "<stdin>", line 17, in <module>
  File "/home/woky/work/test/venv/lib/python3.7/site-packages/tabulate.py", line 1268, in tabulate
    if tablefmt in multiline_formats and _is_multiline(plain_text):
TypeError: unhashable type: 'list'
```

(I'm not the original issue submitter - this is copied from https://bitbucket.org/astanin/python-tabulate/issues/156/custom-tableformat-gives-typeerror)

Comments:

Patch:
diff --git a/tabulate.py b/tabulate.py
index 92164fb..99b6118 100755
--- a/tabulate.py
+++ b/tabulate.py
@@ -1423,7 +1423,11 @@ def tabulate(
 
     has_invisible = re.search(_invisible_codes, plain_text)
     enable_widechars = wcwidth is not None and WIDE_CHARS_MODE
-    if tablefmt in multiline_formats and _is_multiline(plain_text):
+    if (
+        not isinstance(tablefmt, TableFormat)
+        and tablefmt in multiline_formats
+        and _is_multiline(plain_text)
+    ):
         tablefmt = multiline_formats.get(tablefmt, tablefmt)
         is_multiline = True
     else:


Test patch:
diff --git a/test/test_regression.py b/test/test_regression.py
index 8cdfcb2..e79aad8 100644
--- a/test/test_regression.py
+++ b/test/test_regression.py
@@ -4,7 +4,7 @@
 
 from __future__ import print_function
 from __future__ import unicode_literals
-from tabulate import tabulate, _text_type, _long_type
+from tabulate import tabulate, _text_type, _long_type, TableFormat, Line, DataRow
 from common import assert_equal, assert_in, SkipTest
 
 
@@ -365,3 +365,21 @@ def test_empty_pipe_table_with_columns():
     expected = "\n".join(["| Col1   | Col2   |", "|--------|--------|"])
     result = tabulate(table, headers, tablefmt="pipe")
     assert_equal(result, expected)
+
+
+def test_custom_tablefmt():
+    "Regression: allow custom TableFormat that specifies with_header_hide (github issue #20)"
+    tablefmt = TableFormat(
+        lineabove=Line("", "-", "  ", ""),
+        linebelowheader=Line("", "-", "  ", ""),
+        linebetweenrows=None,
+        linebelow=Line("", "-", "  ", ""),
+        headerrow=DataRow("", "  ", ""),
+        datarow=DataRow("", "  ", ""),
+        padding=0,
+        with_header_hide=["lineabove", "linebelow"],
+    )
+    rows = [["foo", "bar"], ["baz", "qux"]]
+    expected = "\n".join(["A    B", "---  ---", "foo  bar", "baz  qux"])
+    result = tabulate(rows, headers=["A", "B"], tablefmt=tablefmt)
+    assert_equal(result, expected)