Commit 5626e87b authored by Stefan Behnel's avatar Stefan Behnel

merge

parents 600d3302 85bdf910
......@@ -917,7 +917,7 @@ class StringNode(PyConstNode):
is_identifier = None
def coerce_to(self, dst_type, env):
if dst_type is not py_object_type and dst_type is not str_type:
if dst_type is not py_object_type and not str_type.subtype_of(dst_type):
# if dst_type is Builtin.bytes_type:
# # special case: bytes = 'str literal'
# return BytesNode(self.pos, value=self.value)
......
......@@ -400,8 +400,11 @@ class BuiltinObjectType(PyObjectType):
return src_type.name == self.name or (
src_type.name == self.alternative_name and
src_type.name is not None)
elif src_type.is_extension_type:
return (src_type.module_name == '__builtin__' and
src_type.name == self.name)
else:
return not src_type.is_extension_type
return True
def typeobj_is_available(self):
return True
......
......@@ -856,7 +856,7 @@ if __name__ == '__main__':
os.path.join(sys.prefix, 'lib', 'python'+sys.version[:3], 'test'),
'pyregr'))
unittest.TextTestRunner(verbosity=options.verbosity).run(test_suite)
result = unittest.TextTestRunner(verbosity=options.verbosity).run(test_suite)
if options.coverage:
coverage.stop()
......@@ -875,3 +875,5 @@ if __name__ == '__main__':
if options.with_refnanny:
import refnanny
sys.stderr.write("\n".join([repr(x) for x in refnanny.reflog]))
sys.exit(not result.wasSuccessful())
cdef extern from *:
ctypedef class __builtin__.list [object PyListObject]:
pass
cdef list foo = []
# This is too invasive for Python 0.11.x, re-enable in 0.12
NEW_ERRORS = u"""
:2:4: list already a builtin Cython type
"""
_ERRORS = u"""
5:16: Cannot coerce list to type 'list'
"""
cdef extern from "Python.h":
ctypedef class __builtin__.str [object PyStringObject]:
cdef long ob_shash
ctypedef class __builtin__.list [object PyListObject]:
cdef Py_ssize_t ob_size
cdef Py_ssize_t allocated
ctypedef class __builtin__.dict [object PyDictObject]:
pass
cdef str s = "abc"
cdef list L = [1,2,4]
cdef dict d = {'A': 'a'}
def test_list(list L):
"""
>>> test_list(range(10))
True
>>> class list_subclass(list): pass
>>> test_list(list_subclass([1,2,3]))
True
"""
return L.ob_size <= L.allocated
def test_str(str s):
"""
>>> test_str("abc")
True
>>> class str_subclass(str): pass
>>> test_str(str_subclass("xyz"))
True
"""
cdef char* ss = s
return hash(s) == s.ob_shash
def test_tuple(tuple t):
"""
Actual builtin types are restrictive wrt subclassing so optimizations can be safely performed.
>>> test_tuple((1,2))
2
>>> class tuple_subclass(tuple): pass
>>> test_tuple(tuple_subclass((1,2)))
Traceback (most recent call last):
...
TypeError: Argument 't' has incorrect type (expected tuple, got tuple_subclass)
"""
return len(t)
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