Lisandro Dalcin wrote: > If we do 'isinstance(obj, str)', then what should be the behavior in > Py2 and Py3? In fact, this question is actually related to the map in > builtin_types_table at Cython/Compiler/Builtin.py. Do it make sense to > do the map like this > > bytes -> PyBytes_Type > str -> PyString_Type > unicode -> PyUnicode_Type
It doesn't make sense for some applications of str. Python 3.0 uses PyUnicode for identifiers (attribute names, function and class names etc.) while Python 2.x uses PyString. You can use PyUnicode instances for attributes in Python 2.x through obj.__dict__[u"key"] = key but you cannot use PyBytes in 3.0. This mapping makes more sense for me: bytes:: whatever Python uses to store binary data Python 2.x: PyString Python 3.x: PyBytes unicode:: text data PyUnicode for all Python versions str:: whatever Python uses for attributes and names Python 2.x: PyString Python 3.x: PyUnicode The suggestion follows my forward compatibility code for Python 2.6. In Python 2.6 b"" and bytes are simple aliases for PyString. "from __future__ import unicode_literals" turns "" into PyUnicode objects. Christian _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
