Source code for codegrade.models.attest_defense_example_question
"""The module that defines the ``AttestDefenseExampleQuestion`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from ..utils import to_dict
[docs]
@dataclass(kw_only=True)
class AttestDefenseExampleQuestion:
"""An example of a question the teacher wants the defense to ask."""
#: The dimension the question probes.
dimension: t.Literal[
"correction", "direction", "ownership", "verification"
]
#: The text of the question.
text: str
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: rqa.FixedMapping(
rqa.RequiredArgument(
"dimension",
rqa.StringEnum(
"correction", "direction", "ownership", "verification"
),
doc="The dimension the question probes.",
),
rqa.RequiredArgument(
"text",
rqa.SimpleValue.str,
doc="The text of the question.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"dimension": to_dict(self.dimension),
"text": to_dict(self.text),
}
return res
@classmethod
def from_dict(
cls: t.Type[AttestDefenseExampleQuestion], d: t.Dict[str, t.Any]
) -> AttestDefenseExampleQuestion:
parsed = cls.data_parser.try_parse(d)
res = cls(
dimension=parsed.dimension,
text=parsed.text,
)
res.raw_data = d
return res