32 lines
760 B
Python
32 lines
760 B
Python
import ast
|
|
from type_def import *
|
|
from top_level import *
|
|
|
|
test = """
|
|
class A:
|
|
a: int
|
|
def foo(a: B):
|
|
pass
|
|
|
|
class B(A):
|
|
a: str
|
|
def bar(self, a: list[list[virtual[A]]]) -> self:
|
|
pass
|
|
"""
|
|
|
|
variables = {'X': TypeVariable('X', []), 'Y': TypeVariable('Y', [])}
|
|
types = {'int': PrimitiveType('int'), 'str': PrimitiveType('str')}
|
|
ctx = Context(variables, types)
|
|
|
|
ctx, _ = parse_top_level(ctx, ast.parse(test))
|
|
|
|
for name, t in ctx.types.items():
|
|
if isinstance(t, ClassType):
|
|
print(f"class {t.name}")
|
|
for name, ty in t.fields.items():
|
|
print(f" {name}: {ty}")
|
|
for name, (args, result, _) in t.methods.items():
|
|
print(f" {name}: ({', '.join([str(v) for v in args])}) -> {result}")
|
|
|
|
|