mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
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
|
||||
|
||||
def _extract_annot(self, function, annot, kind, call_loc, fn_kind):
|
||||
if annot is None:
|
||||
annot = builtins.TNone()
|
||||
|
||||
if not isinstance(annot, types.Type):
|
||||
diag = diagnostic.Diagnostic("error",
|
||||
"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)
|
||||
return x+y
|
||||
|
||||
@kernel
|
||||
def bar(x: TInt64) -> None:
|
||||
print(x)
|
||||
|
||||
@kernel
|
||||
def entrypoint():
|
||||
print(foo(0, 2))
|
||||
print(foo(1, 3))
|
||||
bar(3)
|
||||
|
@ -4,9 +4,9 @@
|
||||
from artiq.experiment import *
|
||||
|
||||
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
|
||||
def hello(self, x: None):
|
||||
def hello(self, x: float):
|
||||
pass
|
||||
|
||||
@kernel
|
||||
|
Loading…
Reference in New Issue
Block a user