Skip to content

Commit 69f67cd

Browse files
DimitriPapadopoulosastanin
authored andcommitted
Do not call getattr with a constant value
It is not any safer than normal property access. It feels like the intent might have been `hasattr()` instead of `getattr()`, but the initial commit e2086c3 appears to : - assume any attribute `dtype` is of type `numpy.dtype`, - test whether `numpy.dtype.names` is a list of fields names or `None`. https://numpy.org/doc/stable/reference/generated/numpy.dtype.names.html
1 parent b96c59a commit 69f67cd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tabulate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
15341534
elif (
15351535
headers == "keys"
15361536
and hasattr(tabular_data, "dtype")
1537-
and getattr(tabular_data.dtype, "names")
1537+
and tabular_data.dtype.names
15381538
):
15391539
# numpy record array
15401540
headers = tabular_data.dtype.names

0 commit comments

Comments
 (0)