Skip to content

Commit

Permalink
Merge pull request #43 from jmanuel1/mypy-kind-compare
Browse files Browse the repository at this point in the history
Don't use total_ordering for the partial ordering of kinds
  • Loading branch information
jmanuel1 authored Nov 16, 2024
2 parents 5019a9f + 5e0f4f6 commit 7616c11
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions concat/typecheck/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
format_rigid_variable_error,
)
from concat.typecheck.substitutions import Substitutions
import functools
from typing import (
AbstractSet,
Any,
Expand Down Expand Up @@ -526,9 +525,9 @@ def constrain_and_bind_variables(
):
return Substitutions([(supertype, self)])
if not isinstance(supertype, GenericType):
supertype_parameter_kinds: Sequence[Kind]
supertype_parameter_kinds: list[Kind]
if isinstance(supertype.kind, GenericTypeKind):
supertype_parameter_kinds = supertype.kind.parameter_kinds
supertype_parameter_kinds = [*supertype.kind.parameter_kinds]
elif self.kind.result_kind <= supertype.kind:
supertype_parameter_kinds = []
else:
Expand All @@ -538,8 +537,8 @@ def constrain_and_bind_variables(
params_to_inst = len(self.kind.parameter_kinds) - len(
supertype_parameter_kinds
)
param_kinds_left = self.kind.parameter_kinds[
-len(supertype_parameter_kinds) :
param_kinds_left = [
*self.kind.parameter_kinds[-len(supertype_parameter_kinds) :]
]
if params_to_inst < 0 or not (
param_kinds_left >= supertype_parameter_kinds
Expand Down Expand Up @@ -1681,8 +1680,6 @@ def type_arguments(self) -> Sequence[Type]:
return [self._type_argument]


# FIXME: Not a total order, using total_ordering might be very unsound.
@functools.total_ordering
class Kind(abc.ABC):
@abc.abstractmethod
def __eq__(self, other: object) -> bool:
Expand All @@ -1692,6 +1689,12 @@ def __eq__(self, other: object) -> bool:
def __lt__(self, other: 'Kind') -> bool:
pass

def __le__(self, other: Kind) -> bool:
return self == other or self < other

def __ge__(self, other: Kind) -> bool:
return other <= self

@abc.abstractmethod
def __str__(self) -> str:
pass
Expand Down

0 comments on commit 7616c11

Please sign in to comment.