I'm trying to annotate a transformation decorator that builds a dynamic data-class with the inclusion of several new functions. I'm trying to make use of dataclass_transform
function but I'm not sure what the best way to design the typehints are.
To clear things up here's a simple example:
import types
from typing import *
class Field:
"""Custom Dataclass Field"""
...
class Base:
"""Custom Dataclass base for additional functions"""
__fields__: List[Field]
def encode(self) -> bytes:
...
@classmethod
def decode(cls, data: bytes) -> Self:
...
T = TypeVar('T')
@dataclass_transform()
def transform(newclass: Type[T]) -> ?:
return types.new_class('test', (newclass, Base), {})
I'm trying to figure out the ?
portion at the end of the transform
function.
So far from my research, I can't seem to find any existing type annotations that really support returning a type with dynamic multiple-inheritance. Maybe some combination of Type
, NewType
, or Generic
will work? Is there a way to do this in any form? Any help is appreciated. Thanks!