summaryrefslogtreecommitdiff
path: root/tests/errors/e_typing_errors.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/errors/e_typing_errors.pyx')
-rw-r--r--tests/errors/e_typing_errors.pyx59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/errors/e_typing_errors.pyx b/tests/errors/e_typing_errors.pyx
new file mode 100644
index 000000000..832f68d90
--- /dev/null
+++ b/tests/errors/e_typing_errors.pyx
@@ -0,0 +1,59 @@
+# mode: error
+
+import cython
+
+try:
+ from typing import Optional, ClassVar
+except ImportError:
+ pass
+
+
+# not OK
+
+def optional_cython_types(Optional[cython.int] i, Optional[cython.double] d, Optional[cython.float] f,
+ Optional[cython.complex] c, Optional[cython.long] l, Optional[cython.longlong] ll):
+ pass
+
+
+MyStruct = cython.struct(a=cython.int, b=cython.double)
+
+def optional_cstruct(Optional[MyStruct] x):
+ pass
+
+
+def optional_pytypes(Optional[int] i, Optional[float] f, Optional[complex] c, Optional[long] l):
+ pass
+
+
+cdef ClassVar[list] x
+
+
+# OK
+
+def optional_memoryview(double[:] d, Optional[double[:]] o):
+ pass
+
+
+cdef class Cls(object):
+ cdef ClassVar[list] x
+
+
+
+_ERRORS = """
+13:42: typing.Optional[...] cannot be applied to non-Python type int
+13:66: typing.Optional[...] cannot be applied to non-Python type double
+13:93: typing.Optional[...] cannot be applied to non-Python type float
+14:42: typing.Optional[...] cannot be applied to non-Python type double complex
+14:70: typing.Optional[...] cannot be applied to non-Python type long
+14:95: typing.Optional[...] cannot be applied to non-Python type long long
+24:30: typing.Optional[...] cannot be applied to non-Python type int
+24:47: typing.Optional[...] cannot be applied to non-Python type float
+24:87: typing.Optional[...] cannot be applied to non-Python type long
+
+20:30: typing.Optional[...] cannot be applied to non-Python type MyStruct
+
+28:20: Modifier 'typing.ClassVar' is not allowed here.
+
+# FIXME: this should be ok :-?
+33:52: typing.Optional[...] cannot be applied to non-Python type double[:]
+"""