Source code for codegrade.models.patch_attest_defense_question_frame
"""The module that defines the ``PatchAttestDefenseQuestionFrame`` 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 .. import parsers
from ..utils import to_dict
from .attest_defense_dimension_weights import AttestDefenseDimensionWeights
[docs]
@dataclass(kw_only=True)
class PatchAttestDefenseQuestionFrame:
""" """
#: How often the defense asks about each dimension.
weights: AttestDefenseDimensionWeights
#: The number of questions the defense asks.
count: int
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(
"weights",
parsers.ParserFor.make(AttestDefenseDimensionWeights),
doc="How often the defense asks about each dimension.",
),
rqa.RequiredArgument(
"count",
rqa.SimpleValue.int,
doc="The number of questions the defense asks.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"weights": to_dict(self.weights),
"count": to_dict(self.count),
}
return res
@classmethod
def from_dict(
cls: t.Type[PatchAttestDefenseQuestionFrame], d: t.Dict[str, t.Any]
) -> PatchAttestDefenseQuestionFrame:
parsed = cls.data_parser.try_parse(d)
res = cls(
weights=parsed.weights,
count=parsed.count,
)
res.raw_data = d
return res