Passed
Push — main ( 29cf9a...076e2b )
by Máté
02:00 queued 46s
created

question   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 35
dl 0
loc 48
rs 10
c 0
b 0
f 0
1
# future: report false positive to JetBrains developers
2
# noinspection PyPackages
3
# future: report false positive to mypy developers
4
from pydantic import BaseModel
5
6
# noinspection PyPackages
7
from .grading_types import GradingType  # type: ignore
8
9
# noinspection PyPackages
10
# future: report false positive to mypy developers
11
from .question_types import QuestionType  # type: ignore
12
13
14
class Question(BaseModel):
15
    q_type: QuestionType
16
    text: str
17
    illustration: bool
18
    answers: list[str]
19
    correct_answers: set[int]
20
    grading: GradingType | None = None
21
22
    def __str__(self) -> str:
23
        text = f"== {self.text} =="
24
        if self.illustration:
25
            text += "\n[[Fájl:.png|keret|keretnélküli|500x500px]]"
26
        ordered_correct_answers = list(self.correct_answers)
27
        ordered_correct_answers.sort()
28
        text += (
29
            f"\n{{{{kvízkérdés|típus={self.q_type.value}"
30
            f"|válasz={",".join([str(answer) for answer in ordered_correct_answers])}"
31
        )
32
        if self.grading:
33
            text += f"|pontozás={self.grading}"
34
        text += "}}"
35
        for answer in self.answers:
36
            text += f"\n# {answer.replace("\n", " ")}"
37
        return text
38
39
    def __hash__(self) -> int:
40
        return hash(
41
            frozenset(
42
                (
43
                    self.q_type,
44
                    self.text,
45
                    self.answers.sort(),
46
                    frozenset(self.correct_answers),
47
                    self.grading,
48
                )
49
            )
50
        )
51