|
7 | 7 | import itertools
|
8 | 8 | import re
|
9 | 9 | import textwrap as textw
|
10 |
| -from typing import List, Iterable, Optional, Tuple, Union, Callable |
| 10 | +from typing import List, Iterable, Optional, Tuple, Union, Callable, Sequence |
11 | 11 |
|
12 | 12 | from wcwidth import wcswidth
|
13 | 13 |
|
|
18 | 18 | except ImportError:
|
19 | 19 | from typing import Container, Generic, Sized, TypeVar
|
20 | 20 |
|
| 21 | + T_co = TypeVar('T_co', covariant=True) |
21 | 22 | # Python 3.5
|
22 | 23 | # noinspection PyAbstractClass
|
23 |
| - class Collection(Generic[TypeVar('T_co', covariant=True)], Container, Sized, Iterable): |
| 24 | + class Collection(Generic[T_co], Container, Sized, Iterable): |
24 | 25 | """hack to enable Collection typing"""
|
25 | 26 | __slots__ = ()
|
26 | 27 |
|
@@ -997,13 +998,18 @@ def generate_table(self, entries: Iterable[Union[Iterable, object]], force_trans
|
997 | 998 | else:
|
998 | 999 | # check if this is a tuple containing a dictionary of decorated values. If so, the row object
|
999 | 1000 | # is the first element a the decorated values is the second element.
|
1000 |
| - if len(entry) == 2 and isinstance(entry[1], dict): |
1001 |
| - entry_obj = entry[0] |
1002 |
| - else: |
| 1001 | + is_tagged = False |
| 1002 | + try: |
| 1003 | + if isinstance(entry, Sequence) and len(entry) == 2 and isinstance(entry[1], dict): |
| 1004 | + entry_obj = entry[0] |
| 1005 | + is_tagged = True |
| 1006 | + else: |
| 1007 | + entry_obj = entry |
| 1008 | + except KeyError: |
1003 | 1009 | entry_obj = entry
|
1004 | 1010 | if self._row_tagger is not None:
|
1005 | 1011 | entry_opts = self._row_tagger(entry_obj)
|
1006 |
| - if len(entry) == 2 and isinstance(entry[1], dict): |
| 1012 | + if is_tagged: |
1007 | 1013 | entry_opts.update(entry[1])
|
1008 | 1014 |
|
1009 | 1015 | for column_index, attrib_name in enumerate(self._column_attribs):
|
|
0 commit comments