From 182dffadfd3308382bd78fdfc86a68c32a1c6826 Mon Sep 17 00:00:00 2001 From: Cameron Riddell Date: Fri, 14 Feb 2025 12:06:57 -0800 Subject: [PATCH] perf avoid try/except in _hasattr_static --- narwhals/utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/narwhals/utils.py b/narwhals/utils.py index cd9eb00e44..e3d71e7867 100644 --- a/narwhals/utils.py +++ b/narwhals/utils.py @@ -1277,11 +1277,8 @@ def dtype_matches_time_unit_and_time_zone( def _hasattr_static(obj: Any, attr: str) -> bool: - try: - getattr_static(obj, attr) - except AttributeError: - return False - return True + sentinel = object() + return getattr_static(obj, attr, sentinel) is not sentinel def is_compliant_dataframe(obj: Any) -> TypeIs[CompliantDataFrame]: