Skip to content

Fix #124. Improve error reporting when non-iterable data provided. - #233

Merged
astanin merged 1 commit into
astanin:masterfrom
ilya112358:add_msg_when_not_iterable
Sep 26, 2024
Merged

astanin merged 1 commit into
astanin:masterfrom
ilya112358:add_msg_when_not_iterable

Conversation

@ilya112358

Copy link
Copy Markdown
Contributor

Fix #124. Also related to #208 and #191.

This is to provide an additional message to the user when the program throws a ... is not iterable exception.

Two blocks of try-except added: one for the case when a non-iterable is passed and another when an iterable of non-iterables is passed.

Typical output:

>>> print(tabulate({"a": 1, "b": 2}))
Traceback (most recent call last):
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 1373, in _normalize_tabular_data
    izip_longest(*tabular_data.values())
TypeError: 'int' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 2080, in tabulate
    list_of_lists, headers = _normalize_tabular_data(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 1376, in _normalize_tabular_data
    raise TypeError(err_msg)
TypeError:

To build a table python-tabulate requires two-dimensional data like a list of lists or similar.
Did you forget a pair of extra [] or ',' in ()?
>>>

@astanin
astanin merged commit f660f66 into astanin:master Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error reporting when tabular_data is a dict of non-iterable values

2 participants