33 lines
887 B
Python
33 lines
887 B
Python
import uuid
|
|
from dataclasses import dataclass
|
|
from typing import Generic, Optional, Protocol, TypeVar
|
|
|
|
from option import Option
|
|
|
|
C = TypeVar("C", default=str)
|
|
V = TypeVar("V", default=str)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class QuizTaskGeneratorMetadata(Generic[C, V]):
|
|
name: Option[str] = Option.maybe(None)
|
|
description: Option[str] = Option.maybe(None)
|
|
id: uuid.UUID = uuid.uuid4()
|
|
|
|
@staticmethod
|
|
def from_values(
|
|
name: Optional[str] = None,
|
|
description: Optional[str] = None,
|
|
) -> "QuizTaskGeneratorMetadata[C, V]":
|
|
return QuizTaskGeneratorMetadata(
|
|
name=Option.maybe(name),
|
|
description=Option.maybe(description),
|
|
)
|
|
|
|
|
|
class TaskGenerator(Protocol, Generic[C, V]):
|
|
metadata: QuizTaskGeneratorMetadata[C, V]
|
|
default_amount: Option[int] = Option.maybe(None)
|
|
|
|
def generate(self) -> QuizTask[C, V]: ...
|