From 1cedf6f8f706803402a544e9c8a458106aec5521 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Sun, 9 Feb 2025 11:54:39 +0100 Subject: [PATCH 1/5] (chore) add type hints to codec abc --- numcodecs/abc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/numcodecs/abc.py b/numcodecs/abc.py index 5aba8c25..6c8ef38b 100644 --- a/numcodecs/abc.py +++ b/numcodecs/abc.py @@ -29,14 +29,14 @@ """ from abc import ABC, abstractmethod -from typing import Optional +from typing import ClassVar class Codec(ABC): """Codec abstract base class.""" # override in sub-class - codec_id: Optional[str] = None + codec_id: ClassVar[str] """Codec identifier.""" @abstractmethod @@ -106,14 +106,14 @@ def from_config(cls, config): # keyword arguments without any special decoding return cls(**config) - def __eq__(self, other): + def __eq__(self, other: object) -> bool: # override in sub-class if need special equality comparison try: - return self.get_config() == other.get_config() + return self.get_config() == other.get_config() # type: ignore[attr-defined] except AttributeError: return False - def __repr__(self): + def __repr__(self) -> str: # override in sub-class if need special representation # by default, assume all non-private members are configuration From d64b509c2f9133af767d211fb624cd553987cc4a Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Wed, 12 Feb 2025 10:47:07 +0100 Subject: [PATCH 2/5] don't check if the abc is registered in test_all_classes_registered --- numcodecs/abc.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/numcodecs/abc.py b/numcodecs/abc.py index 6c8ef38b..a57c13e2 100644 --- a/numcodecs/abc.py +++ b/numcodecs/abc.py @@ -35,7 +35,6 @@ class Codec(ABC): """Codec abstract base class.""" - # override in sub-class codec_id: ClassVar[str] """Codec identifier.""" @@ -106,14 +105,14 @@ def from_config(cls, config): # keyword arguments without any special decoding return cls(**config) - def __eq__(self, other: object) -> bool: + def __eq__(self, other): # override in sub-class if need special equality comparison try: - return self.get_config() == other.get_config() # type: ignore[attr-defined] + return self.get_config() == other.get_config() except AttributeError: return False - def __repr__(self) -> str: + def __repr__(self): # override in sub-class if need special representation # by default, assume all non-private members are configuration From 98e293ca30c5b7b4e7726b2225684b8c460f9b52 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Wed, 12 Feb 2025 11:35:06 +0100 Subject: [PATCH 3/5] don't check if the abc is registered in test_all_classes_registered --- numcodecs/tests/test_registry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numcodecs/tests/test_registry.py b/numcodecs/tests/test_registry.py index 93ed8f03..b5863eb3 100644 --- a/numcodecs/tests/test_registry.py +++ b/numcodecs/tests/test_registry.py @@ -34,6 +34,7 @@ def test_all_classes_registered(): if ( inspect.isclass(obj) and issubclass(obj, numcodecs.abc.Codec) + and hasattr(obj, 'codec_id') and obj.codec_id not in numcodecs.registry.codec_registry and obj.codec_id is not None # remove `None` ) From d8597650c309a5e0c10d846a817eaf53175b86e0 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Wed, 12 Feb 2025 11:45:59 +0100 Subject: [PATCH 4/5] don't check for null codec_id --- numcodecs/tests/test_registry.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numcodecs/tests/test_registry.py b/numcodecs/tests/test_registry.py index b5863eb3..131b8773 100644 --- a/numcodecs/tests/test_registry.py +++ b/numcodecs/tests/test_registry.py @@ -36,7 +36,6 @@ def test_all_classes_registered(): and issubclass(obj, numcodecs.abc.Codec) and hasattr(obj, 'codec_id') and obj.codec_id not in numcodecs.registry.codec_registry - and obj.codec_id is not None # remove `None` ) } From 5cc31dffb29cf1e6fe339bafbc6287a3bb26eb62 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 28 Feb 2025 15:32:35 +0000 Subject: [PATCH 5/5] Update numcodecs/tests/test_registry.py --- numcodecs/tests/test_registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/tests/test_registry.py b/numcodecs/tests/test_registry.py index 131b8773..f6f33e05 100644 --- a/numcodecs/tests/test_registry.py +++ b/numcodecs/tests/test_registry.py @@ -34,7 +34,7 @@ def test_all_classes_registered(): if ( inspect.isclass(obj) and issubclass(obj, numcodecs.abc.Codec) - and hasattr(obj, 'codec_id') + and obj is not numcodecs.abc.Codec and obj.codec_id not in numcodecs.registry.codec_registry ) }