__doc__ = u"""
>>> a = A()
>>> a.foo()
- (True, 'yo')
+ (True, u'yo')
>>> a.foo(False)
- (False, 'yo')
- >>> a.foo(10, 'yes')
- (True, 'yes')
+ (False, u'yo')
+ >>> a.foo(10, u'yes')
+ (True, u'yes')
+
+ >>> call0()
+ (True, u'yo')
+ >>> call1()
+ (False, u'yo')
+ >>> call2()
+ (False, u'go')
"""
+import sys
+
+if sys.version_info[0] >= 3:
+ __doc__ = __doc__.replace(u"u'", u"'")
+
cdef class A:
- cpdef foo(self, bint a=True, b="yo"):
+ cpdef foo(self, bint a=True, b=u"yo"):
return a, b
+
+def call0():
+ a = A()
+ return a.foo()
+
+def call1():
+ a = A()
+ return a.foo(False)
+
+def call2():
+ a = A()
+ return a.foo(False, u"go")
class IteratorAndIterateable:
def next(self):
- raise ValueError("")
+ raise ValueError
+ def __next__(self):
+ raise ValueError
def __iter__(self):
return self
try:
for x in IteratorAndIterateable():
pass
- assert False, "Should not reach this point, iterator has thrown exception"
+ assert False, u"Should not reach this point, iterator has thrown exception"
except ValueError:
pass
__doc__ = u"""
>>> test_ints(100)
(100, 100, 100)
- >>> test_chars("yo")
- ('a', 'bc', 'yo')
- >>> test_chars(None)
+ >>> test_chars(b'yo')
+ (b'a', b'bc', b'yo')
+ >>> test_chars(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
- ...
- TypeError: expected string or Unicode object, NoneType found
+ TypeError: expected ...
>>> test_struct(-5, -10)
-5 -10 True
1 2 False
"""
+import sys
+
+if sys.version_info[0] < 3:
+ __doc__ = __doc__.replace(u"b'", u"'")
+
def test_ints(int x):
cdef list L = [1,2,3,x]
cdef int* Li = [1,2,3,x]
__doc__ = u"""
- >>> do_slice("abcdef".encode(u"ASCII"), 2, 3)
- ('c', 'cdef', 'ab', 'abcdef')
- >>> do_slice("abcdef".encode(u"ASCII"), 0, 5)
- ('abcde', 'abcdef', '', 'abcdef')
+ >>> do_slice(b"abcdef", 2, 3)
+ (b'c', b'cdef', b'ab', b'abcdef')
+ >>> do_slice(b"abcdef", 0, 5)
+ (b'abcde', b'abcdef', b'', b'abcdef')
"""
+import sys
+
+if sys.version_info[0] < 3:
+ __doc__ = __doc__.replace(u"(b'", u"('").replace(u" b'", u" '")
+
def do_slice(s, int i, int j):
cdef char* ss = s
return ss[i:j], ss[i:], ss[:i], ss[:]