From a3be114ac3d638a3b3da7e96f399c7968be135b3 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 13 Sep 2025 15:49:24 +0200 Subject: [PATCH] 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 --- tabulate/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index e100c09..9670947 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1523,7 +1523,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"): elif ( headers == "keys" and hasattr(tabular_data, "dtype") - and getattr(tabular_data.dtype, "names") + and tabular_data.dtype.names ): # numpy record array headers = tabular_data.dtype.names