Skip to content

Commit

Permalink
type system: Fix for Any type
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Dec 31, 2023
1 parent a67d0f5 commit c5f0898
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions runtype/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit c5f0898

Please sign in to comment.