answer.Answer.__eq__()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
from ...illustrations.illustration import Illustration  # type: ignore
2
from ...quiz_element import QuizElement  # type: ignore
3
4
5
class Answer(QuizElement):
6
    def __init__(
7
        self, text: str, correct: bool, illustration: Illustration | None = None
8
    ) -> None:
9
        super().__init__(text, illustration)
10
11
        assert isinstance(correct, bool)
12
        self.correct = correct
13
14
    def __hash__(self) -> int:
15
        object_hash = hash(frozenset((self.text, self.correct, self.illustration)))
16
        return object_hash
17
18
    def __eq__(self, other: object) -> bool:
19
        if not isinstance(other, Answer):
20
            return False
21
        return (
22
            self.text == other.text
23
            and self.correct == other.correct
24
            and self.illustration == other.illustration
25
        )
26