From 80ff11eb722ac194e57e5fe18752b9ce2ad862dc Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 7 Apr 2011 14:18:47 +0200 Subject: [PATCH] extended test cases for type inference in generators --- tests/run/generator_type_inference.pyx | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/run/generator_type_inference.pyx b/tests/run/generator_type_inference.pyx index d8c7c852..6a5c90e9 100644 --- a/tests/run/generator_type_inference.pyx +++ b/tests/run/generator_type_inference.pyx @@ -5,9 +5,48 @@ cimport cython def test_type_inference(): """ - >>> [ item for item in test_type_inference() ] + >>> list(test_type_inference()) [(2.0, 'double'), (2.0, 'double'), (2.0, 'double')] """ x = 1.0 for i in range(3): yield x * 2.0, cython.typeof(x) + +def test_unicode_loop(): + """ + >>> chars = list(test_unicode_loop()) + 1 Py_UCS4 + 2 Py_UCS4 + 2 Py_UCS4 + 2 Py_UCS4 + 2 Py_UCS4 + >>> len(chars) + 4 + >>> ''.join(chars) == 'abcd' + True + """ + ustr = u'abcd' + print 1, cython.typeof(ustr[0]) + for c in ustr: + print 2, cython.typeof(c) + yield c + +def test_nonlocal_disables_inference(): + """ + >>> chars = list(test_nonlocal_disables_inference()) + 1 Python object + 2 Python object + 2 Python object + >>> len(chars) + 2 + >>> ''.join(chars) == 'ab' + True + """ + ustr = u'ab' + print 1, cython.typeof(ustr[0]) + def gen(): + nonlocal ustr + for c in ustr: + print 2, cython.typeof(c) + yield c + return gen() -- 2.26.2