Source code for codegrade.models.patch_attest_defense_policy

"""The module that defines the ``PatchAttestDefensePolicy`` 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_ai_use_rules import AttestDefenseAiUseRules
from .attest_defense_any_ai_tool import AttestDefenseAnyAiTool
from .patch_attest_defense_only_ai_tools import PatchAttestDefenseOnlyAiTools


[docs] @dataclass(kw_only=True) class PatchAttestDefensePolicy: """ """ #: The rule for each use of AI. rules: AttestDefenseAiUseRules #: The AI tools the student may use. allowed_tools: t.Union[ PatchAttestDefenseOnlyAiTools, AttestDefenseAnyAiTool ] #: The policy as the teacher wrote it. policy_text: str #: What the student must disclose about their use of AI. disclosure_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( "rules", parsers.ParserFor.make(AttestDefenseAiUseRules), doc="The rule for each use of AI.", ), rqa.RequiredArgument( "allowed_tools", parsers.make_union( parsers.ParserFor.make(PatchAttestDefenseOnlyAiTools), parsers.ParserFor.make(AttestDefenseAnyAiTool), ), doc="The AI tools the student may use.", ), rqa.RequiredArgument( "policy_text", rqa.SimpleValue.str, doc="The policy as the teacher wrote it.", ), rqa.RequiredArgument( "disclosure_text", rqa.SimpleValue.str, doc="What the student must disclose about their use of AI.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "rules": to_dict(self.rules), "allowed_tools": to_dict(self.allowed_tools), "policy_text": to_dict(self.policy_text), "disclosure_text": to_dict(self.disclosure_text), } return res @classmethod def from_dict( cls: t.Type[PatchAttestDefensePolicy], d: t.Dict[str, t.Any] ) -> PatchAttestDefensePolicy: parsed = cls.data_parser.try_parse(d) res = cls( rules=parsed.rules, allowed_tools=parsed.allowed_tools, policy_text=parsed.policy_text, disclosure_text=parsed.disclosure_text, ) res.raw_data = d return res