Cython v0.29 Release Notes

Release Date: 2018-10-14 // over 5 years ago
  • ๐Ÿ”‹ Features added

    • PEP-489 multi-phase module initialisation has been enabled again. Module reloads in other subinterpreters raise an exception to prevent corruption of the static module state.

    • A set of mypy compatible PEP-484 declarations were added for Cython's C data types to integrate with static analysers in typed Python code. They are available in the Cython/Shadow.pyi module and describe the types in the special cython module that can be used for typing in Python code. Original patch by Julian Gethmann. (Github issue :issue:1965)

    • ๐Ÿ’… Memoryviews are supported in PEP-484/526 style type declarations. (Github issue :issue:2529)

    • ๐Ÿ‘ @cython.nogil is supported as a C-function decorator in Python code. (Github issue :issue:2557)

    • Raising exceptions from nogil code will automatically acquire the GIL, instead of requiring an explicit with gil block.

    • C++ functions can now be declared as potentially raising both C++ and Python exceptions, so that Cython can handle both correctly. (Github issue :issue:2615)

    • ๐Ÿ‘ cython.inline() supports a direct language_level keyword argument that was previously only available via a directive.

    • A new language level name 3str was added that mostly corresponds to language level 3, but keeps unprefixed string literals as type 'str' in both Py2 and Py3, and the builtin 'str' type unchanged. This will become the default in the next Cython release and is meant to help user code a) transition more easily to this new default and b) migrate to Python 3 source code semantics without making support for Python 2.x difficult.

    • In CPython 3.6 and later, looking up globals in the module dict is almost as fast as looking up C globals. (Github issue :issue:2313)

    • For a Python subclass of an extension type, repeated method calls to non-overridden cpdef methods can avoid the attribute lookup in Py3.6+, which makes them 4x faster. (Github issue :issue:2313)

    • (In-)equality comparisons of objects to integer literals are faster. (Github issue :issue:2188)

    • Some internal and 1-argument method calls are faster.

    • Modules that cimport many external extension types from other Cython modules execute less import requests during module initialisation.

    • Constant tuples and slices are deduplicated and only created once per module. (Github issue :issue:2292)

    • ๐Ÿ”Œ The coverage plugin considers more C file extensions such as .cc and .cxx. (Github issue :issue:2266)

    • The cythonize command accepts compile time variable values (as set by DEF) through the new -E option. Patch by Jerome Kieffer. (Github issue :issue:2315)

    • ๐Ÿ“ฆ pyximport can import from namespace packages. Patch by Prakhar Goel. (Github issue :issue:2294)

    • Some missing numpy and CPython C-API declarations were added. Patch by John Kirkham. (Github issues :issue:2523, :issue:2520, :issue:2537)

    • Declarations for the pylifecycle C-API functions were added in a new .pxd file cpython.pylifecycle.

    • โšก๏ธ The Pythran support was updated to work with the latest Pythran 0.8.7. Original patch by Adrien Guinet. (Github issue :issue:2600)

    • %a is included in the string formatting types that are optimised into f-strings. In this case, it is also automatically mapped to %r in Python 2.x.

    • New C macro CYTHON_HEX_VERSION to access Cython's version in the same style as PY_VERSION_HEX.

    • Constants in libc.math are now declared as const to simplify their handling.

    • An additional check_size clause was added to the ctypedef class name specification to allow suppressing warnings when importing modules with backwards-compatible PyTypeObject size changes. Patch by Matti Picus. (Github issue :issue:2627)

    ๐Ÿ› Bugs fixed

    • ๐Ÿ‘ป The exception handling in generators and coroutines under CPython 3.7 was adapted to the newly introduced exception stack. Users of Cython 0.28 who want to support Python 3.7 are encouraged to upgrade to 0.29 to avoid potentially incorrect error reporting and tracebacks. (Github issue :issue:1958)

    • Crash when importing a module under Stackless Python that was built for CPython. Patch by Anselm Kruis. (Github issue :issue:2534)

    • 2-value slicing of typed sequences failed if the start or stop index was None. Patch by Christian Gibson. (Github issue :issue:2508)

    • Multiplied string literals lost their factor when they are part of another constant expression (e.g. 'x' * 10 + 'y' => 'xy').

    • String formatting with the '%' operator didn't call the special __rmod__() method if the right side is a string subclass that implements it. (Python issue 28598)

    • The directive language_level=3 did not apply to the first token in the source file. (Github issue :issue:2230)

    • Overriding cpdef methods did not work in Python subclasses with slots. Note that this can have a performance impact on calls from Cython code. (Github issue :issue:1771)

    • ๐Ÿ›  Fix declarations of builtin or C types using strings in pure python mode. (Github issue :issue:2046)

    • Generator expressions and lambdas failed to compile in @cfunc functions. (Github issue :issue:459)

    • Global names with const types were not excluded from star-import assignments which could lead to invalid C code. (Github issue :issue:2621)

    • โš  Several internal function signatures were fixed that lead to warnings in gcc-8. (Github issue :issue:2363)

    • The numpy helper functions set_array_base() and get_array_base() were adapted to the current numpy C-API recommendations. Patch by Matti Picus. (Github issue :issue:2528)

    • โšก๏ธ Some NumPy related code was updated to avoid deprecated API usage. Original patch by jbrockmendel. (Github issue :issue:2559)

    • Several C++ STL declarations were extended and corrected. Patch by Valentin Valls. (Github issue :issue:2207)

    • C lines of the module init function were unconditionally not reported in exception stack traces. Patch by Jeroen Demeyer. (Github issue :issue:2492)

    • ๐Ÿ‘ When PEP-489 support is enabled, reloading the module overwrote any static module state. It now raises an exception instead, given that reloading is not actually supported.

    • ๐Ÿ‘ป Object-returning, C++ exception throwing functions were not checking that the return value was non-null. Original patch by Matt Wozniski (Github issue :issue:2603)

    • The source file encoding detection could get confused if the c_string_encoding directive appeared within the first two lines. (Github issue :issue:2632)

    • โš  Cython generated modules no longer emit a warning during import when the size of the NumPy array type is larger than what was found at compile time. Instead, this is assumed to be a backwards compatible change on NumPy side.

    Other changes

    • โš  Cython now emits a warning when no language_level (2, 3 or '3str') is set explicitly, neither as a cythonize() option nor as a compiler directive. This is meant to prepare the transition of the default language level from currently Py2 to Py3, since that is what most new users will expect these days. The future default will, however, not enforce unicode literals, because this has proven a major obstacle in the support for both Python 2.x and 3.x. The next major release is intended to make this change, so that it will parse all code that does not request a specific language level as Python 3 code, but with str literals. The language level 2 will continue to be supported for an indefinite time.

    • ๐Ÿ“š The documentation was restructured, cleaned up and examples are now tested. The NumPy tutorial was also rewritten to simplify the running example. Contributed by Gabriel de Marmiesse. (Github issue :issue:2245)

    • ๐Ÿ— Cython compiles less of its own modules at build time to reduce the installed package size to about half of its previous size. This makes the compiler slightly slower, by about 5-7%.