Commit 30e86670 authored by Tom Niget's avatar Tom Niget

Add helper class for displaying synthesized annotations in unparsed code

parent fab94334
...@@ -11,7 +11,7 @@ from transpiler.phases.typing.class_ import ScoperClassVisitor ...@@ -11,7 +11,7 @@ from transpiler.phases.typing.class_ import ScoperClassVisitor
from transpiler.phases.typing.scope import VarDecl, VarKind, ScopeKind, Scope from transpiler.phases.typing.scope import VarDecl, VarKind, ScopeKind, Scope
from transpiler.phases.typing.types import BaseType, TypeVariable, FunctionType, \ from transpiler.phases.typing.types import BaseType, TypeVariable, FunctionType, \
Promise, TY_NONE, PromiseKind, TupleType, UserType, TypeType, ModuleType Promise, TY_NONE, PromiseKind, TupleType, UserType, TypeType, ModuleType
from transpiler.phases.utils import PlainBlock from transpiler.phases.utils import PlainBlock, AnnotationName
@dataclass @dataclass
...@@ -141,7 +141,7 @@ class ScoperBlockVisitor(ScoperVisitor): ...@@ -141,7 +141,7 @@ class ScoperBlockVisitor(ScoperVisitor):
def annotate_arg(self, arg: ast.arg) -> BaseType: def annotate_arg(self, arg: ast.arg) -> BaseType:
if arg.annotation is None: if arg.annotation is None:
res = TypeVariable() res = TypeVariable()
arg.annotation = ast.Name(id=str(res), ctx=ast.Load()) arg.annotation = AnnotationName(res)
return res return res
else: else:
return self.visit_annotation(arg.annotation) return self.visit_annotation(arg.annotation)
......
...@@ -30,4 +30,15 @@ class NodeVisitorSeq: ...@@ -30,4 +30,15 @@ class NodeVisitorSeq:
@dataclass @dataclass
class PlainBlock(ast.stmt): class PlainBlock(ast.stmt):
body: list[ast.stmt] body: list[ast.stmt]
\ No newline at end of file
@dataclass
class AnnotationName:
inner: "transpiler.phases.typing.types.BaseType"
@property
def id(self):
return str(self.inner)
AnnotationName.__name__ = "Name"
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment