|
6 | 6 |
|
7 | 7 | from abc import ABC, abstractmethod |
8 | 8 | from collections.abc import AsyncIterator |
9 | | -from typing import TypeVar |
| 9 | +from typing import Generic, TypeVar |
10 | 10 |
|
| 11 | +TInput = TypeVar("TInput") |
11 | 12 | T = TypeVar("T") |
12 | 13 |
|
13 | 14 |
|
14 | | -class AsyncTransformer(ABC, AsyncIterator[T]): |
| 15 | +class AsyncTransformer(ABC, AsyncIterator[T], Generic[TInput, T]): |
15 | 16 | """Base class for image processing middleware.""" |
16 | 17 |
|
17 | | - def __init__(self, source: AsyncIterator[bytes]) -> None: |
| 18 | + def __init__(self, source: AsyncIterator[TInput]) -> None: |
18 | 19 | """Initialize with source iterator.""" |
19 | 20 | self.source = source |
20 | 21 |
|
21 | 22 | @abstractmethod |
22 | | - async def transform(self, data: bytes) -> T: |
23 | | - """Transform the image bytes.""" |
| 23 | + async def transform(self, data: TInput) -> T: |
| 24 | + """Asynchronously transform a single chunk of input data. |
| 25 | +
|
| 26 | + Args: |
| 27 | + data (bytes): The input data to be transformed, typically |
| 28 | + representing image bytes. |
| 29 | +
|
| 30 | + Returns: |
| 31 | + T: The transformed output, as defined by the subclass |
| 32 | + implementation. |
| 33 | +
|
| 34 | + Raises: |
| 35 | + NotImplementedError: If the method is not implemented by a subclass. |
| 36 | +
|
| 37 | + """ |
24 | 38 | message = "Subclasses must implement this method" |
25 | 39 | raise NotImplementedError(message) |
26 | 40 |
|
|
0 commit comments