From 5cf3a2506c5a6b302537c32d7efbacbfbf4cc1ee Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Tue, 15 Oct 2024 15:59:03 +0300 Subject: [PATCH] Fix eq/hash for copies of types --- runtype/base_types.py | 1 + runtype/pytypes.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/runtype/base_types.py b/runtype/base_types.py index 53e319b..e2f55d9 100644 --- a/runtype/base_types.py +++ b/runtype/base_types.py @@ -52,6 +52,7 @@ def __mul__(self, other: _Type): def __le__(self, other): return NotImplemented + class AnyType(Type): """Represents the Any type. diff --git a/runtype/pytypes.py b/runtype/pytypes.py index b96a506..822f734 100644 --- a/runtype/pytypes.py +++ b/runtype/pytypes.py @@ -177,6 +177,15 @@ def cast_from(self, obj): return obj + def __eq__(self, other): + if type(other) != type(self): + return False + return self.kernel == other.kernel + + def __hash__(self): + return hash((type(self), self.kernel)) + + class TupleType(PythonType): def test_instance(self, obj, sampler=None): return isinstance(obj, tuple)