Source code for codegrade.models.parse_error_all_of

"""The module that defines the ``ParseErrorAllOf`` 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


[docs] @dataclass class ParseErrorAllOf: """JSON shape of `AllOf`.""" #: Discriminator tag. kind: t.Literal["all-of"] #: At most `_MAX_CHILDREN` positional failures, in encounter order. errors: t.Sequence[ParseErrorAt] #: Total number of failures before capping. total_errors: int #: `True` if `total_errors` exceeded `_MAX_CHILDREN` and `errors` was #: truncated. truncated: bool 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( "kind", rqa.StringEnum("all-of"), doc="Discriminator tag.", ), rqa.RequiredArgument( "errors", rqa.List(parsers.ParserFor.make(ParseErrorAt)), doc="At most `_MAX_CHILDREN` positional failures, in encounter order.", ), rqa.RequiredArgument( "total_errors", rqa.SimpleValue.int, doc="Total number of failures before capping.", ), rqa.RequiredArgument( "truncated", rqa.SimpleValue.bool, doc="`True` if `total_errors` exceeded `_MAX_CHILDREN` and `errors` was truncated.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "kind": to_dict(self.kind), "errors": to_dict(self.errors), "total_errors": to_dict(self.total_errors), "truncated": to_dict(self.truncated), } return res @classmethod def from_dict( cls: t.Type[ParseErrorAllOf], d: t.Dict[str, t.Any] ) -> ParseErrorAllOf: parsed = cls.data_parser.try_parse(d) res = cls( kind=parsed.kind, errors=parsed.errors, total_errors=parsed.total_errors, truncated=parsed.truncated, ) res.raw_data = d return res
from .parse_error_at import ParseErrorAt