feat(checker): add top type (Any)
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
||||
from midas.checker.types import (
|
||||
BaseType,
|
||||
GenericType,
|
||||
TopType,
|
||||
Type,
|
||||
TypeVar,
|
||||
UnitType,
|
||||
@@ -40,6 +41,7 @@ def basic_op(reg: TypesRegistry, type: Type, op: str):
|
||||
|
||||
def define_builtins(reg: TypesRegistry):
|
||||
"""Define builtin types and operations"""
|
||||
any = reg.define_type("Any", TopType())
|
||||
unit = reg.define_type("None", UnitType())
|
||||
object = reg.define_type("object", BaseType(name="object"))
|
||||
bool = reg.define_type("bool", BaseType(name="bool"))
|
||||
|
||||
@@ -12,6 +12,7 @@ from midas.checker.types import (
|
||||
GenericType,
|
||||
Operation,
|
||||
OverloadedFunction,
|
||||
TopType,
|
||||
Type,
|
||||
TypeVar,
|
||||
UnknownType,
|
||||
@@ -155,6 +156,9 @@ class TypesRegistry:
|
||||
return True
|
||||
|
||||
match (type1, type2):
|
||||
case (_, TopType()):
|
||||
return True
|
||||
|
||||
case (AliasType(type=base1), _):
|
||||
return self.is_subtype(base1, type2)
|
||||
|
||||
|
||||
@@ -4,6 +4,12 @@ from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class TopType:
|
||||
def __str__(self) -> str:
|
||||
return "Any"
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class BaseType:
|
||||
name: str
|
||||
@@ -222,7 +228,8 @@ def unfold_type(type: Type) -> Type:
|
||||
|
||||
|
||||
Type = (
|
||||
BaseType
|
||||
TopType
|
||||
| BaseType
|
||||
| AliasType
|
||||
| UnknownType
|
||||
| UnitType
|
||||
|
||||
Reference in New Issue
Block a user