summaryrefslogtreecommitdiff
path: root/tests/errors
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2022-01-30 12:59:19 +0100
committerStefan Behnel <stefan_ml@behnel.de>2022-01-30 12:59:19 +0100
commitf73108cc1d459486a8040796ae2a3e7fc2964ff3 (patch)
tree5898e50839243cbcb73ac0c7ee6971872d2e6d81 /tests/errors
parentaaba122938f0837869d16a1fc8f5d8859d54bc62 (diff)
downloadcython-f73108cc1d459486a8040796ae2a3e7fc2964ff3.tar.gz
Check for "Optional[ctype]" earlier because we need to make sure that "Optional[int]" etc. interprets "int" as (valid) Python int type and not (invalid) C int type.
See https://github.com/cython/cython/issues/3883
Diffstat (limited to 'tests/errors')
-rw-r--r--tests/errors/e_typing_optional.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/tests/errors/e_typing_optional.py b/tests/errors/e_typing_optional.py
index e75638e00..6facfeea4 100644
--- a/tests/errors/e_typing_optional.py
+++ b/tests/errors/e_typing_optional.py
@@ -8,11 +8,10 @@ except ImportError:
pass
-def optional_pytypes(i: Optional[int], f: Optional[float]):
- pass
-
+# not OK
-def optional_cython_types(i: Optional[cython.int], d: Optional[cython.double], f: Optional[cython.float]):
+def optional_cython_types(i: Optional[cython.int], d: Optional[cython.double], f: Optional[cython.float],
+ c: Optional[cython.complex], l: Optional[cython.long], ll: Optional[cython.longlong]):
pass
@@ -22,13 +21,23 @@ def optional_cstruct(x: Optional[MyStruct]):
pass
+# OK
+
+def optional_pytypes(i: Optional[int], f: Optional[float], c: Optional[complex], l: Optional[long]):
+ pass
+
+
+def optional_memoryview(d: double[:], o: Optional[double[:]]):
+ pass
+
+
_ERRORS = """
-15:29: Only Python type arguments can use typing.Optional[...]
-15:54: Only Python type arguments can use typing.Optional[...]
-15:82: Only Python type arguments can use typing.Optional[...]
-21:24: Only Python type arguments can use typing.Optional[...]
-
-# FIXME: these should be allowed!
-11:24: Only Python type arguments can use typing.Optional[...]
-11:42: Only Python type arguments can use typing.Optional[...]
+13:44: typing.Optional[...] cannot be applied to non-Python type int
+13:69: typing.Optional[...] cannot be applied to non-Python type double
+13:97: typing.Optional[...] cannot be applied to non-Python type float
+14:44: typing.Optional[...] cannot be applied to non-Python type double complex
+14:73: typing.Optional[...] cannot be applied to non-Python type long
+14:100: typing.Optional[...] cannot be applied to non-Python type long long
+
+20:33: typing.Optional[...] cannot be applied to non-Python type MyStruct
"""