Skip to content

Commit 86a9719

Browse files
sophiawisdompre-commit-ci[bot]behackl
authored
Add __hash__ to ManimColor (#4051)
* add __hash__ to ManimColor * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * add test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: correct typehint * fix test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent 97f818e commit 86a9719

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: manim/utils/color/core.py

+3
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,9 @@ def __xor__(self, other: Self) -> Self:
10301030
self._internal_from_integer(self.to_integer() ^ int(other), 1.0)
10311031
)
10321032

1033+
def __hash__(self) -> int:
1034+
return hash(self.to_hex(with_alpha=True))
1035+
10331036

10341037
RGBA = ManimColor
10351038
"""RGBA Color Space"""

Diff for: tests/module/utils/test_color.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from manim import BLACK, Mobject, Scene, VMobject
5+
from manim import BLACK, RED, WHITE, ManimColor, Mobject, Scene, VMobject
66

77

88
def test_import_color():
@@ -49,3 +49,9 @@ def test_set_color():
4949
assert m.color.to_hex() == "#FFFFFF"
5050
m.set_color(BLACK)
5151
assert m.color.to_hex() == "#000000"
52+
53+
54+
def test_color_hash():
55+
assert hash(WHITE) == hash(ManimColor([1.0, 1.0, 1.0, 1.0]))
56+
assert hash(WHITE) == hash("#FFFFFFFF")
57+
assert hash(WHITE) != hash(RED)

0 commit comments

Comments
 (0)