summaryrefslogtreecommitdiff
path: root/tests/run/cython3.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/cython3.pyx')
-rw-r--r--tests/run/cython3.pyx68
1 files changed, 46 insertions, 22 deletions
diff --git a/tests/run/cython3.pyx b/tests/run/cython3.pyx
index c7ad56f87..dcc250ae0 100644
--- a/tests/run/cython3.pyx
+++ b/tests/run/cython3.pyx
@@ -16,6 +16,7 @@ x = u'abc'
>>> except_as_deletes
True
+
>>> no_match_does_not_touch_target
True
"""
@@ -25,11 +26,24 @@ IS_PY2 = sys.version_info[0] < 3
if not IS_PY2:
__doc__ = __doc__.replace(" u'", " '")
+
def locals_function(a, b=2):
x = 'abc'
return locals()
+### "new style" classes
+
+class T:
+ """
+ >>> t = T()
+ >>> isinstance(t, T)
+ True
+ >>> isinstance(T, type) # not a Py2 old style class!
+ True
+ """
+
+
### true division
def truediv(x):
@@ -340,7 +354,7 @@ def unicode_literals():
def non_ascii_unprefixed_str():
- u"""
+ """
>>> s = non_ascii_unprefixed_str()
>>> isinstance(s, bytes)
False
@@ -353,7 +367,7 @@ def non_ascii_unprefixed_str():
def non_ascii_raw_str():
- u"""
+ """
>>> s = non_ascii_raw_str()
>>> isinstance(s, bytes)
False
@@ -366,7 +380,7 @@ def non_ascii_raw_str():
def non_ascii_raw_prefixed_unicode():
- u"""
+ """
>>> s = non_ascii_raw_prefixed_unicode()
>>> isinstance(s, bytes)
False
@@ -604,25 +618,27 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar
>>> len(annotation_syntax.__annotations__)
5
>>> print(annotation_syntax.__annotations__['a'])
- test new test
+ 'test new test'
>>> print(annotation_syntax.__annotations__['b'])
- other
+ 'other'
>>> print(annotation_syntax.__annotations__['args'])
- ARGS
+ 'ARGS'
>>> print(annotation_syntax.__annotations__['kwargs'])
- KWARGS
+ 'KWARGS'
>>> print(annotation_syntax.__annotations__['return'])
- ret
+ 'ret'
"""
result : int = a + b
return result
-def builtin_as_annotation(text: str):
+@cython.annotation_typing(False)
+def builtin_as_ignored_annotation(text: str):
+ # Used to crash the compiler when annotation typing is disabled.
# See https://github.com/cython/cython/issues/2811
"""
- >>> builtin_as_annotation("abc")
+ >>> builtin_as_ignored_annotation("abc")
a
b
c
@@ -631,24 +647,32 @@ def builtin_as_annotation(text: str):
print(c)
+@cython.annotation_typing(True)
+def int_annotation(x: int) -> int:
+ """
+ >>> print(int_annotation(1))
+ 2
+ >>> print(int_annotation(10))
+ 1024
+ >>> print(int_annotation(100))
+ 1267650600228229401496703205376
+ >>> print(int_annotation((10 * 1000 * 1000) // 1000 // 1000)) # 'long' arg in Py2
+ 1024
+ >>> print(int_annotation((100 * 1000 * 1000) // 1000 // 1000)) # 'long' arg in Py2
+ 1267650600228229401496703205376
+ """
+ return 2 ** x
+
+
+@cython.annotation_typing(True)
async def async_def_annotations(x: 'int') -> 'float':
"""
>>> ret, arg = sorted(async_def_annotations.__annotations__.items())
>>> print(ret[0]); print(ret[1])
return
- float
+ 'float'
>>> print(arg[0]); print(arg[1])
x
- int
+ 'int'
"""
return float(x)
-
-
-'''
-def repr_returns_str(x) -> str:
- """
- >>> repr_returns_str(123)
- '123'
- """
- return repr(x)
-'''