Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) Type hints for abc codec codec_id attribute #702

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions numcodecs/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
"""

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
Expand Down
2 changes: 1 addition & 1 deletion numcodecs/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_all_classes_registered():
if (
inspect.isclass(obj)
and issubclass(obj, numcodecs.abc.Codec)
and hasattr(obj, 'codec_id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and hasattr(obj, 'codec_id')
and obj is not numcodecs.abc.Codec

I think is a bit clearer in intent (we don't want or need the base codec to be registered)?

and obj.codec_id not in numcodecs.registry.codec_registry
and obj.codec_id is not None # remove `None`
)
}

Expand Down
Loading