Repository: astanin/python-tabulate (python)

Issue:
SEPARATING_LINE does not work with dataclasses
Using tabulate to print a list of dataclasses when one or more rows is SEPARATING_LINE, produces:

```
  File "....\.venv\lib\site-packages\tabulate\__init__.py", line 1451, in <listcomp>
    rows = [[getattr(row, f) for f in field_names] for row in rows ]
AttributeError: 'str' object has no attribute '<the first attribute of dataclass>'
```

Can be assigned to me, I have a fix.

Pull request:
Fix separating line with dataclasses
Closes #267 

Patch:
diff --git a/tabulate/__init__.py b/tabulate/__init__.py
index 11bb865..f95da8e 100644
--- a/tabulate/__init__.py
+++ b/tabulate/__init__.py
@@ -1461,7 +1461,12 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
             field_names = [field.name for field in dataclasses.fields(rows[0])]
             if headers == "keys":
                 headers = field_names
-            rows = [[getattr(row, f) for f in field_names] for row in rows]
+            rows = [
+                [getattr(row, f) for f in field_names]
+                if not _is_separating_line(row)
+                else row
+                for row in rows
+            ]
 
         elif headers == "keys" and len(rows) > 0:
             # keys are column indices


Test patch:
diff --git a/test/test_input.py b/test/test_input.py
index a178bd9..d52f10b 100644
--- a/test/test_input.py
+++ b/test/test_input.py
@@ -1,6 +1,6 @@
 """Test support of the various forms of tabular data."""
 
-from tabulate import tabulate
+from tabulate import tabulate, SEPARATING_LINE
 from common import assert_equal, assert_in, raises, skip
 
 try:
@@ -520,6 +520,28 @@ def test_py37orlater_list_of_dataclasses_headers():
         skip("test_py37orlater_list_of_dataclasses_headers is skipped")
 
 
+def test_py37orlater_list_of_dataclasses_with_separating_line():
+    "Input: a list of dataclasses with a separating line"
+    try:
+        from dataclasses import make_dataclass
+
+        Person = make_dataclass("Person", ["name", "age", "height"])
+        ld = [Person("Alice", 23, 169.5), SEPARATING_LINE, Person("Bob", 27, 175.0)]
+        result = tabulate(ld, headers="keys")
+        expected = "\n".join(
+            [
+                "name      age    height",
+                "------  -----  --------",
+                "Alice      23     169.5",
+                "------  -----  --------",
+                "Bob        27     175",
+            ]
+        )
+        assert_equal(expected, result)
+    except ImportError:
+        skip("test_py37orlater_list_of_dataclasses_keys is skipped")
+
+
 def test_list_bytes():
     "Input: a list of bytes. (issue #192)"
     lb = [["你好".encode("utf-8")], ["你好"]]