From 6666f6a8a5f1d500712f7f37ca202af6da2f7fe1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 13 Mar 2024 01:04:27 -1000 Subject: [PATCH] Simplify clearing _attr cached_property in entities (#113136) --- homeassistant/helpers/entity.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index f4cc933a6c6..5f31c049d13 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -332,10 +332,7 @@ class CachedProperties(type): Raises AttributeError if the __attr_ attribute does not exist """ # Invalidate the cache of the cached property - try: # noqa: SIM105 suppress is much slower - delattr(o, name) - except AttributeError: - pass + o.__dict__.pop(name, None) # Delete the __attr_ attribute delattr(o, private_attr_name) @@ -354,10 +351,8 @@ class CachedProperties(type): if getattr(o, private_attr_name, _SENTINEL) == val: return setattr(o, private_attr_name, val) - try: # noqa: SIM105 suppress is much slower - delattr(o, name) - except AttributeError: - pass + # Invalidate the cache of the cached property + o.__dict__.pop(name, None) return _setter