forked from M-Labs/artiq
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:
parent
594ff45750
commit
8f518c6b05
|
@ -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",
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue