From c6eda61d4893c3a4d5611c72ab93fb5ce7866b81 Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Fri, 18 Oct 2024 13:41:46 -0400 Subject: [PATCH] Remove try: except: and let badly subclassed items fail --- .../python/chip/clusters/ClusterObjects.py | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/controller/python/chip/clusters/ClusterObjects.py b/src/controller/python/chip/clusters/ClusterObjects.py index c0a0adec1ccacb..beb490c631ab50 100644 --- a/src/controller/python/chip/clusters/ClusterObjects.py +++ b/src/controller/python/chip/clusters/ClusterObjects.py @@ -262,12 +262,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None: """Register a subclass.""" super().__init_subclass__(*args, **kwargs) # register this cluster in the ALL_CLUSTERS dict for quick lookups - try: - ALL_CLUSTERS[cls.id] = cls - except NotImplementedError: - # handle case where the Cluster class is not (fully) subclassed - # and accessing the id property throws a NotImplementedError. - pass + ALL_CLUSTERS[cls.id] = cls @property def data_version(self) -> int: @@ -301,16 +296,11 @@ class ClusterAttributeDescriptor: def __init_subclass__(cls, *args, **kwargs) -> None: """Register a subclass.""" super().__init_subclass__(*args, **kwargs) - try: - if cls.standard_attribute: - if cls.cluster_id not in ALL_ATTRIBUTES: - ALL_ATTRIBUTES[cls.cluster_id] = {} - # register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups - ALL_ATTRIBUTES[cls.cluster_id][cls.attribute_id] = cls - except NotImplementedError: - # handle case where the ClusterAttribute class is not (fully) subclassed - # and accessing the id property throws a NotImplementedError. - pass + if cls.standard_attribute: + if cls.cluster_id not in ALL_ATTRIBUTES: + ALL_ATTRIBUTES[cls.cluster_id] = {} + # register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups + ALL_ATTRIBUTES[cls.cluster_id][cls.attribute_id] = cls @classmethod def ToTLV(cls, tag: Union[int, None], value): @@ -373,15 +363,11 @@ class ClusterEvent(ClusterObject): def __init_subclass__(cls, *args, **kwargs) -> None: """Register a subclass.""" super().__init_subclass__(*args, **kwargs) - try: - if cls.cluster_id not in ALL_EVENTS: - ALL_EVENTS[cls.cluster_id] = {} - # register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups - ALL_EVENTS[cls.cluster_id][cls.event_id] = cls - except NotImplementedError: - # handle case where the ClusterAttribute class is not (fully) subclassed - # and accessing the id property throws a NotImplementedError. - pass + + if cls.cluster_id not in ALL_EVENTS: + ALL_EVENTS[cls.cluster_id] = {} + # register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups + ALL_EVENTS[cls.cluster_id][cls.event_id] = cls @ChipUtility.classproperty def cluster_id(self) -> int: