forked from M-Labs/artiq
1
0
Fork 0

compiler: Allow `None` in type hints

Similar to how Python itself interprets None as type(None),
make it translate to TNone in ARTIQ compiler type hints.
This commit is contained in:
David Nadlinger 2018-06-30 19:51:58 +01:00 committed by Sébastien Bourdeauducq
parent 594ff45750
commit 8f518c6b05
3 changed files with 10 additions and 2 deletions

View File

@ -950,6 +950,9 @@ class Stitcher:
return function_node return function_node
def _extract_annot(self, function, annot, kind, call_loc, fn_kind): def _extract_annot(self, function, annot, kind, call_loc, fn_kind):
if annot is None:
annot = builtins.TNone()
if not isinstance(annot, types.Type): if not isinstance(annot, types.Type):
diag = diagnostic.Diagnostic("error", diag = diagnostic.Diagnostic("error",
"type annotation for {kind}, '{annot}', is not an ARTIQ type", "type annotation for {kind}, '{annot}', is not an ARTIQ type",

View File

@ -11,7 +11,12 @@ def foo(x: TInt64, y: TInt64 = 1) -> TInt64:
print(x+y) print(x+y)
return x+y return x+y
@kernel
def bar(x: TInt64) -> None:
print(x)
@kernel @kernel
def entrypoint(): def entrypoint():
print(foo(0, 2)) print(foo(0, 2))
print(foo(1, 3)) print(foo(1, 3))
bar(3)

View File

@ -4,9 +4,9 @@
from artiq.experiment import * from artiq.experiment import *
class c(): class c():
# CHECK-L: ${LINE:+2}: error: type annotation for argument 'x', 'None', is not an ARTIQ type # CHECK-L: ${LINE:+2}: error: type annotation for argument 'x', '<class 'float'>', is not an ARTIQ type
@kernel @kernel
def hello(self, x: None): def hello(self, x: float):
pass pass
@kernel @kernel