diff --git a/xarray/core/extensions.py b/xarray/core/extensions.py index efe00718a79..c2bf2e94453 100644 --- a/xarray/core/extensions.py +++ b/xarray/core/extensions.py @@ -48,7 +48,9 @@ def __get__(self, obj, cls): def _register_accessor(name, cls): def decorator(accessor): - if hasattr(cls, name): + # Only check for existing attribute if Warn will actually be issued + existing = getattr(cls, name, None) + if existing is not None: warnings.warn( f"registration of accessor {accessor!r} under name {name!r} for type {cls!r} is " "overriding a preexisting attribute with the same name.",