Skip to content

Commit 46eea3b

Browse files
committed
Explicitly set __hash__ for various classes
1 parent 8c36626 commit 46eea3b

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

src/srctools/bsp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class VERSIONS(Enum):
111111
DESOLATION_OLD = 42 # Old version.
112112
VITAMINSOURCE = 43 # Desolation's expanded map format.
113113

114+
def __hash__(self) -> int:
115+
return hash(self.value)
116+
114117
def __eq__(self, other: object) -> bool:
115118
"""Versions are equal to their integer value."""
116119
return self.value == other

src/srctools/dmx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ def __repr__(self) -> str:
10421042
value = repr(self._value)
10431043
return f'<{self._typ.name} Attr {self.name!r}: {value}>'
10441044

1045+
__hash__ = None # type: ignore[assignment]
1046+
10451047
def __eq__(self, other: object) -> builtins.bool:
10461048
if isinstance(other, Attribute):
10471049
return (

src/srctools/fgd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ def overrides(self) -> Collection[HelperTypes]:
534534
"""
535535
return ()
536536

537+
__hash__ = None # type: ignore[assignment]
538+
537539
def __eq__(self, other: object) -> bool:
538540
"""Define equality as all attributes matching, and only matching types."""
539541
if not isinstance(other, Helper):
@@ -998,6 +1000,8 @@ def __init__(self, ent: 'EntityDef', attr_name: str, disp_name: str) -> None:
9981000
def __repr__(self) -> str:
9991001
return f'{self._ent!r}.{self._disp_attr}'
10001002

1003+
__hash__ = None # type: ignore[assignment]
1004+
10011005
def __eq__(self, other: object) -> bool:
10021006
"""We're private, so we should be the only instance for a given Entity."""
10031007
return other is self

src/srctools/keyvalues.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ def as_array(self, *, conv: Callable[[str], T] = cast(Any, str)) -> Union[List[T
774774
else:
775775
return [conv(self._value)]
776776

777+
__hash__ = None # type: ignore[assignment]
778+
777779
def __eq__(self, other: Any) -> builtins.bool:
778780
"""Compare two items and determine if they are equal.
779781

src/srctools/math.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class VecBase:
323323
"""Internal Base class for 3D vectors, implementing common code."""
324324
__match_args__: Final = ('_x', '_y', '_z')
325325
__slots__ = ('_x', '_y', '_z')
326-
__hash__ = None
326+
__hash__ = None # type: ignore[assignment]
327327

328328
#: This is a dictionary containing complementary axes.
329329
#: ``INV_AXIS["x", "y"]`` gives ``"z"``, and ``INV_AXIS["y"]`` returns ``("x", "z")``.
@@ -1193,7 +1193,7 @@ def __reduce__(self) -> Tuple[Callable[[float, float, float], 'FrozenVec'], Tupl
11931193
"""
11941194
return _mk_fvec, (self._x, self._y, self._z)
11951195

1196-
def __hash__(self) -> int:
1196+
def __hash__(self) -> int: # type: ignore[override]
11971197
"""Hashing a frozen vec is the same as hashing the tuple form."""
11981198
return hash((round(self._x, 6), round(self._y, 6), round(self._z, 6)))
11991199

@@ -1627,7 +1627,7 @@ def _from_raw(
16271627
self._ca, self._cb, self._cc = ca, cb, cc
16281628
return self
16291629

1630-
__hash__ = None
1630+
__hash__ = None # type: ignore[assignment]
16311631

16321632
def __eq__(self, other: object) -> bool:
16331633
if isinstance(other, MatrixBase):
@@ -2219,7 +2219,7 @@ class AngleBase:
22192219
# Use the private attrs for matching also, we only hook assignment in the mutable one.
22202220
__match_args__ = ('_pitch', '_yaw', '_roll')
22212221
__slots__ = ('_pitch', '_yaw', '_roll')
2222-
__hash__ = None
2222+
__hash__ = None # type: ignore
22232223

22242224
_pitch: float
22252225
_yaw: float
@@ -2624,7 +2624,7 @@ def __reduce__(self) -> Tuple[Callable[[float, float, float], 'FrozenAngle'], Tu
26242624
"""
26252625
return _mk_fang, (self._pitch, self._yaw, self._roll)
26262626

2627-
def __hash__(self) -> int:
2627+
def __hash__(self) -> int: # type: ignore[override]
26282628
"""Hashing a frozen angle is the same as hashing the tuple form."""
26292629
return hash((round(self._pitch, 6), round(self._yaw, 6), round(self._roll, 6)))
26302630

src/srctools/tokenizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def __init__(
5959
def __repr__(self) -> str:
6060
return f'TokenSyntaxError({self.mess!r}, {self.file!r}, {self.line_num!r})'
6161

62-
__hash__ = None # This is mutable
62+
# This is mutable.
63+
__hash__ = None # type: ignore[assignment]
6364

6465
def __eq__(self, other: object) -> bool:
6566
if isinstance(other, TokenSyntaxError):

0 commit comments

Comments
 (0)