0.20 (2014-01-18)
Features added
- Support for CPython 3.4.
- Support for calling C++ template functions.
yield
is supported infinally
clauses.- The C code generated for finally blocks is duplicated for each exitcase to allow for better optimisations by the C compiler.
- Cython tries to undo the Python optimisationism of assigning a boundmethod to a local variable when it can generate better code for thedirect call.
- Constant Python float values are cached.
- String equality comparisons can use faster type specific code inmore cases than before.
- String/Unicode formatting using the ‘%’ operator uses a fasterC-API call.
bytearray
has become a known type and supports coercion from andto C strings. Indexing, slicing and decoding is optimised. Note thatthis may have an impact on existing code due to type inference.- Using
cdef basestring stringvar
and function arguments typed asbasestring
is now meaningful and allows assigning exactlystr
andunicode
objects, but no subtypes of these types. - Support for the
debug
builtin. - Assertions in Cython compiled modules are disabled if the runningPython interpreter was started with the “-O” option.
- Some types that Cython provides internally, such as functions andgenerators, are now shared across modules if more than one Cythonimplemented module is imported.
- The type inference algorithm works more fine granular by taking theresults of the control flow analysis into account.
- A new script in
bin/cythonize
provides a command line frontendto the cythonize() compilation function (including distutils build). - The new extension type decorator
@cython.no_gc_clear
preventsobjects from being cleared during cyclic garbage collection, thusmaking sure that object attributes are kept alive until deallocation. - During cyclic garbage collection, attributes of extension types thatcannot create reference cycles due to their type (e.g. strings) areno longer considered for traversal or clearing. This can reduce theprocessing overhead when searching for or cleaning up reference cycles.
- Package compilation (i.e.
init.py
files) now works, startingwith Python 3.3. - The cython-mode.el script for Emacs was updated. Patch by Ivan Andrus.
- An option common_utility_include_dir was added to cythonize() to saveoft-used utility code once in a separate directory rather than aspart of each generated file.
unraisable_tracebacks
directive added to control printing oftracebacks of unraisable exceptions.
Bugs fixed
- Abstract Python classes that subtyped a Cython extension typefailed to raise an exception on instantiation, and thus endedup being instantiated.
set.add(a_tuple)
andset.discard(a_tuple)
failed with aTypeError in Py2.4.- The PEP 3155
qualname
was incorrect for nested classes andinner classes/functions declared asglobal
. - Several corner cases in the try-finally statement were fixed.
- The metaclass of a Python class was not inherited from its parentclass(es). It is now extracted from the list of base classes if notprovided explicitly using the Py3
metaclass
keyword argument.In Py2 compilation mode, ametaclass
entry in the classdict will still take precedence if not using Py3 metaclass syntax,but only after creating the class dict (which may have been doneby a metaclass of a base class, see PEP 3115). It is generallyrecommended to use the explicit Py3 syntax to define metaclassesfor Python types at compile time. - The automatic C switch statement generation behaves more safely forheterogeneous value types (e.g. mixing enum and char), allowing fora slightly wider application and reducing corner cases. It now alwaysgenerates a ‘default’ clause to avoid C compiler warnings aboutunmatched enum values.
- Fixed a bug where class hierarchies declared out-of-order could resultin broken generated code.
- Fixed a bug which prevented overriding const methods of C++ classes.
- Fixed a crash when converting Python objects to C++ strings fails.
Other changes
- In Py3 compilation mode, Python2-style metaclasses declared by a
metaclass
class dict entry are ignored. - In Py3.4+, the Cython generator type uses
tp_finalize()
for safercleanup instead oftp_del()
.