Skip to content

Commit a384471

Browse files
authored
Merge pull request #382 from DimitriPapadopoulos/__call__
Robust test for callable objects
2 parents d54e6eb + f967017 commit a384471

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tabulate/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
14911491
index = None
14921492
if hasattr(tabular_data, "keys") and hasattr(tabular_data, "values"):
14931493
# dict-like and pandas.DataFrame?
1494-
if hasattr(tabular_data.values, "__call__"):
1494+
if callable(tabular_data.values):
14951495
# likely a conventional dict
14961496
keys = tabular_data.keys()
14971497
try:
@@ -2557,7 +2557,7 @@ def _build_row(padded_cells, colwidths, colaligns, rowfmt):
25572557
"Return a string which represents a row of data cells."
25582558
if not rowfmt:
25592559
return None
2560-
if hasattr(rowfmt, "__call__"):
2560+
if callable(rowfmt):
25612561
return rowfmt(padded_cells, colwidths, colaligns)
25622562
else:
25632563
return _build_simple_row(padded_cells, rowfmt)
@@ -2608,7 +2608,7 @@ def _build_line(colwidths, colaligns, linefmt):
26082608
"Return a string which represents a horizontal line."
26092609
if not linefmt:
26102610
return None
2611-
if hasattr(linefmt, "__call__"):
2611+
if callable(linefmt):
26122612
return linefmt(colwidths, colaligns)
26132613
else:
26142614
begin, fill, sep, end = linefmt

0 commit comments

Comments
 (0)