Skip to content

Commit d82f1cf

Browse files
committed
type hints for gzip, and necessary changes to Codec abc
1 parent 3cf8ab1 commit d82f1cf

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

numcodecs/abc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@
2929
"""
3030

3131
from abc import ABC, abstractmethod
32-
from typing import Optional
32+
from typing import ClassVar
3333

3434

3535
class Codec(ABC):
3636
"""Codec abstract base class."""
3737

38-
# override in sub-class
39-
codec_id: Optional[str] = None
38+
codec_id: ClassVar[str]
4039
"""Codec identifier."""
4140

4241
@abstractmethod

numcodecs/gzip.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gzip as _gzip
22
import io
3+
from typing import ClassVar, Literal
34

45
from .abc import Codec
56
from .compat import ensure_bytes, ensure_contiguous_ndarray
@@ -15,12 +16,13 @@ class GZip(Codec):
1516
1617
"""
1718

18-
codec_id = 'gzip'
19+
codec_id: ClassVar[Literal['gzip']] = 'gzip'
20+
level: int
1921

2022
def __init__(self, level=1):
2123
self.level = level
2224

23-
def encode(self, buf):
25+
def encode(self, buf) -> bytes:
2426
# normalise inputs
2527
buf = ensure_contiguous_ndarray(buf)
2628

@@ -31,7 +33,7 @@ def encode(self, buf):
3133
return compressed.getvalue()
3234

3335
# noinspection PyMethodMayBeStatic
34-
def decode(self, buf, out=None):
36+
def decode(self, buf, out=None) -> bytes:
3537
# normalise inputs
3638
# BytesIO only copies if the data is not of `bytes` type.
3739
# This allows `bytes` objects to pass through without copying.

0 commit comments

Comments
 (0)