From 8f518c6b055526106dd578d3d8c61d31c9a9d905 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 30 Jun 2018 19:51:58 +0100 Subject: [PATCH] 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. --- artiq/compiler/embedding.py | 3 +++ artiq/test/lit/embedding/annotation.py | 5 +++++ artiq/test/lit/embedding/error_specialized_annot.py | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 2b10673bd..fb0a8be39 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -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", diff --git a/artiq/test/lit/embedding/annotation.py b/artiq/test/lit/embedding/annotation.py index 7e9c05d9f..21ae25332 100644 --- a/artiq/test/lit/embedding/annotation.py +++ b/artiq/test/lit/embedding/annotation.py @@ -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) diff --git a/artiq/test/lit/embedding/error_specialized_annot.py b/artiq/test/lit/embedding/error_specialized_annot.py index c474f235b..2f5955043 100644 --- a/artiq/test/lit/embedding/error_specialized_annot.py +++ b/artiq/test/lit/embedding/error_specialized_annot.py @@ -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', '', is not an ARTIQ type @kernel - def hello(self, x: None): + def hello(self, x: float): pass @kernel