Commit 6008886f authored by Stefan Behnel's avatar Stefan Behnel

Merge branch '0.24.x'

parents 97739979 480bf89f
...@@ -20,8 +20,8 @@ Cython supports four Python string types: :obj:`bytes`, :obj:`str`, ...@@ -20,8 +20,8 @@ Cython supports four Python string types: :obj:`bytes`, :obj:`str`,
:obj:`unicode` and :obj:`basestring`. The :obj:`bytes` and :obj:`unicode` types :obj:`unicode` and :obj:`basestring`. The :obj:`bytes` and :obj:`unicode` types
are the specific types known from normal Python 2.x (named :obj:`bytes` are the specific types known from normal Python 2.x (named :obj:`bytes`
and :obj:`str` in Python 3). Additionally, Cython also supports the and :obj:`str` in Python 3). Additionally, Cython also supports the
:obj:`bytearray` type starting with Python 2.6. It behaves like the :obj:`bytearray` type which behaves like the :obj:`bytes` type, except
:obj:`bytes` type, except that it is mutable. that it is mutable.
The :obj:`str` type is special in that it is the byte string in Python 2 The :obj:`str` type is special in that it is the byte string in Python 2
and the Unicode string in Python 3 (for Cython code compiled with and the Unicode string in Python 3 (for Cython code compiled with
...@@ -55,10 +55,25 @@ Python 2 for backwards compatibility reasons. It is not compatible with ...@@ -55,10 +55,25 @@ Python 2 for backwards compatibility reasons. It is not compatible with
the :obj:`bytes` type. Its usage should be rare in normal Cython code as the :obj:`bytes` type. Its usage should be rare in normal Cython code as
the generic :obj:`object` type (i.e. untyped code) will normally be good the generic :obj:`object` type (i.e. untyped code) will normally be good
enough and has the additional advantage of supporting the assignment of enough and has the additional advantage of supporting the assignment of
string subtypes. Support for the :obj:`basestring` type is new in Cython string subtypes. Support for the :obj:`basestring` type was added in Cython
0.20. 0.20.
String literals
---------------
Cython understands all Python string type prefixes:
* ``b'bytes'`` for byte strings
* ``u'text'`` for Unicode strings
* ``f'formatted {value}'`` for formatted Unicode string literals as defined by
`PEP 498 <https://www.python.org/dev/peps/pep-0498/>`_ (added in Cython 0.24)
Unprefixed string literals become :obj:`str` objects when compiling
with language level 2 and :obj:`unicode` objects (i.e. Python 3
:obj:`str`) with language level 3.
General notes about C strings General notes about C strings
----------------------------- -----------------------------
......
...@@ -277,6 +277,8 @@ A convienient and safe place to do so is in the `__cinit__` and `__dealloc__` me ...@@ -277,6 +277,8 @@ A convienient and safe place to do so is in the `__cinit__` and `__dealloc__` me
which are guaranteed to be called exactly once upon creation and deletion of the Python which are guaranteed to be called exactly once upon creation and deletion of the Python
instance. instance.
::
cdef class PyRectangle: cdef class PyRectangle:
cdef Rectangle* c_rect # hold a pointer to the C++ instance which we're wrapping cdef Rectangle* c_rect # hold a pointer to the C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1): def __cinit__(self, int x0, int y0, int x1, int y1):
......
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