Commit ab17365a authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-devel

parents 5c962c3b f30c3a6b
...@@ -289,7 +289,7 @@ class PyObjectConst(object): ...@@ -289,7 +289,7 @@ class PyObjectConst(object):
possible_unicode_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_unicode_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
possible_bytes_identifier = re.compile(r"(?![0-9])\w+$".encode('ASCII')).match possible_bytes_identifier = re.compile(r"(?![0-9])\w+$".encode('ASCII')).match
nice_identifier = re.compile('^[a-zA-Z0-9_]+$').match nice_identifier = re.compile(r'\A[a-zA-Z0-9_]+\Z').match
find_alphanums = re.compile('([a-zA-Z0-9]+)').findall find_alphanums = re.compile('([a-zA-Z0-9]+)').findall
class StringConst(object): class StringConst(object):
......
This diff is collapsed.
...@@ -2443,6 +2443,9 @@ def spanning_type(type1, type2): ...@@ -2443,6 +2443,9 @@ def spanning_type(type1, type2):
return type1 return type1
elif type1 is py_object_type or type2 is py_object_type: elif type1 is py_object_type or type2 is py_object_type:
return py_object_type return py_object_type
elif type1 is c_py_unicode_type or type2 is c_py_unicode_type:
# Py_UNICODE behaves more like a string than an int
return py_object_type
span_type = _spanning_type(type1, type2) span_type = _spanning_type(type1, type2)
if span_type is None: if span_type is None:
return py_object_type return py_object_type
......
DEF FLOAT = 12.5 DEF FLOAT = 12.5
DEF EFLOAT = 5e-1
DEF FLOAT_NAN = float('nan') DEF FLOAT_NAN = float('nan')
DEF FLOAT_INFP = float('+inf') DEF FLOAT_INFP = float('+inf')
DEF FLOAT_INFN = float('-inf') DEF FLOAT_INFN = float('-inf')
...@@ -20,6 +21,14 @@ def f(): ...@@ -20,6 +21,14 @@ def f():
f = FLOAT f = FLOAT
return f return f
def efloat():
"""
>>> efloat()
0.5
"""
cdef float f = EFLOAT
return f
def nan1(): def nan1():
""" """
>>> nan1() >>> nan1()
......
...@@ -103,6 +103,9 @@ __doc__ = ur""" ...@@ -103,6 +103,9 @@ __doc__ = ur"""
True True
>>> len(u6) >>> len(u6)
7 7
>>> newlines == "Aaa\n"
True
""" """
import sys import sys
...@@ -127,3 +130,5 @@ u3 = ur"abc\x11" ...@@ -127,3 +130,5 @@ u3 = ur"abc\x11"
u4 = Ur"abc\x11" u4 = Ur"abc\x11"
u5 = uR"abc\x11" u5 = uR"abc\x11"
u6 = UR"abc\x11" u6 = UR"abc\x11"
newlines = "Aaa\n"
cimport cython
cdef unicode _ustring = u'azerty123456'
ustring = _ustring
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index(unicode ustring, Py_ssize_t i):
"""
>>> index(ustring, 0)
u'a'
>>> index(ustring, 2)
u'e'
>>> index(ustring, -1)
u'6'
>>> index(ustring, -len(ustring))
u'a'
>>> index(ustring, len(ustring))
Traceback (most recent call last):
IndexError: string index out of range
"""
return ustring[i]
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index_literal(Py_ssize_t i):
"""
>>> index_literal(0)
u'a'
>>> index_literal(2)
u'e'
>>> index_literal(-1)
u'6'
>>> index_literal(-len('azerty123456'))
u'a'
>>> index_literal(len(ustring))
Traceback (most recent call last):
IndexError: string index out of range
"""
return u'azerty123456'[i]
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
@cython.boundscheck(False)
def index_no_boundscheck(unicode ustring, Py_ssize_t i):
"""
>>> index_no_boundscheck(ustring, 0)
u'a'
>>> index_no_boundscheck(ustring, 2)
u'e'
>>> index_no_boundscheck(ustring, -1)
u'6'
>>> index_no_boundscheck(ustring, len(ustring)-1)
u'6'
>>> index_no_boundscheck(ustring, -len(ustring))
u'a'
"""
return ustring[i]
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
@cython.boundscheck(False)
def unsigned_index_no_boundscheck(unicode ustring, unsigned int i):
"""
>>> unsigned_index_no_boundscheck(ustring, 0)
u'a'
>>> unsigned_index_no_boundscheck(ustring, 2)
u'e'
>>> unsigned_index_no_boundscheck(ustring, len(ustring)-1)
u'6'
"""
return ustring[i]
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode",
"//PrimaryCmpNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index_compare(unicode ustring, Py_ssize_t i):
"""
>>> index_compare(ustring, 0)
True
>>> index_compare(ustring, 1)
False
>>> index_compare(ustring, -1)
False
>>> index_compare(ustring, -len(ustring))
True
>>> index_compare(ustring, len(ustring))
Traceback (most recent call last):
IndexError: string index out of range
"""
return ustring[i] == u'a'
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode",
"//PrimaryCmpNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index_compare_string(unicode ustring, Py_ssize_t i, unicode other):
"""
>>> index_compare_string(ustring, 0, ustring[0])
True
>>> index_compare_string(ustring, 0, ustring[:4])
False
>>> index_compare_string(ustring, 1, ustring[0])
False
>>> index_compare_string(ustring, 1, ustring[1])
True
>>> index_compare_string(ustring, -1, ustring[0])
False
>>> index_compare_string(ustring, -1, ustring[-1])
True
>>> index_compare_string(ustring, -len(ustring), ustring[-len(ustring)])
True
>>> index_compare_string(ustring, len(ustring), ustring)
Traceback (most recent call last):
IndexError: string index out of range
"""
return ustring[i] == other
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode",
"//MulNode",
"//MulNode/CoerceToPyTypeNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index_multiply(unicode ustring, Py_ssize_t i, int mul):
"""
>>> ustring[0] * 5
u'aaaaa'
>>> index_multiply(ustring, 0, 5)
u'aaaaa'
"""
return ustring[i] * mul
@cython.test_assert_path_exists("//CoerceToPyTypeNode",
"//IndexNode",
"//AddNode",
"//AddNode/CoerceToPyTypeNode")
@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
def index_add(unicode ustring, Py_ssize_t i, Py_ssize_t j):
"""
>>> ustring[0] + ustring[-1]
u'a6'
>>> index_add(ustring, 0, -1)
u'a6'
"""
return ustring[i] + ustring[j]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment