diff options
Diffstat (limited to 'tests/run/cython3_no_unicode_literals.pyx')
-rw-r--r-- | tests/run/cython3_no_unicode_literals.pyx | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/run/cython3_no_unicode_literals.pyx b/tests/run/cython3_no_unicode_literals.pyx index c9690b305..308de75a5 100644 --- a/tests/run/cython3_no_unicode_literals.pyx +++ b/tests/run/cython3_no_unicode_literals.pyx @@ -4,6 +4,8 @@ print(end='') # test that language_level 3 applies immediately at the module start, for the first token. +import cython + __doc__ = """ >>> items = sorted(locals_function(1).items()) >>> for item in items: @@ -140,7 +142,15 @@ def str_type_is_str(): cdef str s = 'abc' return str, s +def strip_wrapped_string(s): + # PEP 563 translates an annotation of "test new test" to '"test new test"' + # but choice of string delimiters is a bit arbitrary + # this function handles that + assert s[0] == s[-1] # delimiters on either end are the same + return s[1:-1] # strip them + +@cython.annotation_typing(False) def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwargs: "KWARGS") -> "ret": """ >>> annotation_syntax(1) @@ -150,17 +160,26 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar >>> len(annotation_syntax.__annotations__) 5 - >>> annotation_syntax.__annotations__['a'] + >>> strip_wrapped_string(annotation_syntax.__annotations__['a']) 'test new test' - >>> annotation_syntax.__annotations__['b'] + >>> strip_wrapped_string(annotation_syntax.__annotations__['b']) 'other' - >>> annotation_syntax.__annotations__['args'] + >>> strip_wrapped_string(annotation_syntax.__annotations__['args']) 'ARGS' - >>> annotation_syntax.__annotations__['kwargs'] + >>> strip_wrapped_string(annotation_syntax.__annotations__['kwargs']) 'KWARGS' - >>> annotation_syntax.__annotations__['return'] + >>> strip_wrapped_string(annotation_syntax.__annotations__['return']) 'ret' """ result : int = a + b return result + + +@cython.annotation_typing(True) +def repr_returns_str(x) -> str: + """ + >>> repr_returns_str(123) + '123' + """ + return repr(x) |