From c5f0898c509827d66acdd4ae443f993ddd312941 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Sun, 31 Dec 2023 12:15:36 +0700 Subject: [PATCH] type system: Fix for Any type --- runtype/base_types.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/runtype/base_types.py b/runtype/base_types.py index 59ee9d2..ed5af1c 100644 --- a/runtype/base_types.py +++ b/runtype/base_types.py @@ -49,9 +49,11 @@ def __ge__(self, other): return NotImplemented def __le__(self, other): - if isinstance(other, Type): - if other is self: # Optimization - return True + if other is self: # Optimization + return True + elif isinstance(other, (type, Type)): + if not isinstance(other, SumType): + return False return NotImplemented @@ -74,9 +76,6 @@ def __le__(self, other): return super().__le__(other) def __ge__(self, other): - # XXX hack - if isinstance(other, AnyType): - return False return NotImplemented @@ -177,12 +176,6 @@ class ContainerType(DataType): def __getitem__(self, other): return GenericType(self, other) - def __le__(self, other): - # XXX hack - if isinstance(other, AnyType): - return True - return super().__le__(other) - class GenericType(ContainerType): """Implements a generic type. i.e. a container for items of a specific type. @@ -226,10 +219,6 @@ def __le__(self, other): elif isinstance(other, DataType): return self.base <= other - elif isinstance(other, AnyType): - # HACK - return True - return NotImplemented def __ge__(self, other): @@ -239,10 +228,6 @@ def __ge__(self, other): elif isinstance(other, DataType): return self.base >= other - elif isinstance(other, AnyType): - # HACK - return False - return NotImplemented def __hash__(self):