fix(types): remove unused operation structures

This commit is contained in:
2026-06-13 18:57:02 +02:00
parent ac620f318b
commit 04c0d683de
3 changed files with 0 additions and 95 deletions

View File

@@ -6,7 +6,6 @@ from midas.checker.types import (
BaseType, BaseType,
GenericType, GenericType,
TopType, TopType,
Type,
TypeVar, TypeVar,
UnitType, UnitType,
) )
@@ -21,24 +20,6 @@ BUILTIN_SUBTYPES: dict[str, set[str]] = {
} }
def op(reg: TypesRegistry, t1: Type, operator: str, t2: Type, t3: Type):
reg.define_operation(
left=t1,
operator=operator,
right=t2,
result=t3,
)
def basic_op(reg: TypesRegistry, type: Type, op: str):
reg.define_operation(
left=type,
operator=op,
right=type,
result=type,
)
def define_builtins(reg: TypesRegistry): def define_builtins(reg: TypesRegistry):
"""Define builtin types and operations""" """Define builtin types and operations"""
any = reg.define_type("Any", TopType()) any = reg.define_type("Any", TopType())

View File

@@ -10,7 +10,6 @@ from midas.checker.types import (
ExtensionType, ExtensionType,
Function, Function,
GenericType, GenericType,
Operation,
OverloadedFunction, OverloadedFunction,
TopType, TopType,
Type, Type,
@@ -25,7 +24,6 @@ class TypesRegistry:
self.logger: logging.Logger = logging.getLogger("TypesRegistry") self.logger: logging.Logger = logging.getLogger("TypesRegistry")
self._types: dict[str, Type] = {} self._types: dict[str, Type] = {}
self._members: dict[str, dict[str, Type]] = {} self._members: dict[str, dict[str, Type]] = {}
self._operations: dict[Operation.CallSignature, Type] = {}
def get_type(self, name: str) -> Type: def get_type(self, name: str) -> Type:
"""Get a type from its name """Get a type from its name
@@ -43,39 +41,6 @@ class TypesRegistry:
return self._types[name] return self._types[name]
raise NameError(f"Undefined type {name}") raise NameError(f"Undefined type {name}")
def get_operation_result(
self, left: Type, operator: str, right: Type
) -> Optional[Type]:
"""Get the resulting type of an operation
Args:
left (Type): the type of the left operand
operator (str): the operation name
right (Type): the type of the right operand
Returns:
Optional[Type]: the result type, or None if no matching operation was found
"""
signature: Operation.CallSignature = Operation.CallSignature(
left=left,
method=operator,
right=right,
)
result: Optional[Type] = self._operations.get(signature)
return result
def get_operations_by_name(self, name: str) -> list[Operation]:
operations: list[Operation] = []
for signature, result in self._operations.items():
if signature.method == name:
operations.append(
Operation(
signature=signature,
result=result,
)
)
return operations
def define_type(self, name: str, type: Type) -> Type: def define_type(self, name: str, type: Type) -> Type:
"""Define a type in the registry """Define a type in the registry
@@ -116,29 +81,6 @@ class TypesRegistry:
else: else:
members[member_name] = member_type members[member_name] = member_type
def define_operation(self, left: Type, operator: str, right: Type, result: Type):
"""Define an operation in the registry
Args:
left (Type): the type of the left operand
operator (str): the operation name
right (Type): the type of the right operand
result (Type): the result type
Raises:
ValueError: if an operation is already defined with these operands and name
"""
signature: Operation.CallSignature = Operation.CallSignature(
left=left,
method=operator,
right=right,
)
if signature in self._operations:
raise ValueError(
f"Operation {operator} already defined between {left} and {right}"
)
self._operations[signature] = result
def is_subtype(self, type1: Type, type2: Type) -> bool: def is_subtype(self, type1: Type, type2: Type) -> bool:
"""Check whether `type1` is a subtype of `type2` """Check whether `type1` is a subtype of `type2`

View File

@@ -101,24 +101,6 @@ class ExtensionType:
return f"{self.base} & {self.extension}" return f"{self.base} & {self.extension}"
@dataclass(frozen=True, kw_only=True)
class Operation:
signature: CallSignature
result: Type
def __str__(self) -> str:
return f"{self.signature} -> {self.result}"
@dataclass(frozen=True, kw_only=True)
class CallSignature:
left: Type
method: str
right: Type
def __str__(self) -> str:
return f"{self.method}({self.left}, {self.right})"
@dataclass(frozen=True, kw_only=True) @dataclass(frozen=True, kw_only=True)
class TypeVar: class TypeVar:
name: str name: str