来源:Cython
浏览 524
扫码
分享
2020-04-04 08:24:09
0.27 (2017-09-23)
Features added
- Extension module initialisation followsPEP 489 in CPython 3.5+, whichresolves several differences with regard to normal Python modules. This makesthe global names
file
and path
correctly available to modulelevel code and improves the support for module-level relative imports.(Github issues #1715, #1753, #1035) - Asynchronous generators (PEP 525)and asynchronous comprehensions (PEP 530)have been implemented. Note that async generators require finalisation supportin order to allow for asynchronous operations during cleanup, which is onlyavailable in CPython 3.6+. All other functionality has been backported as usual.
- Variable annotations are now parsed according toPEP 526. Cython types (e.g.
cython.int
) are evaluated as C type declarations and everything else as Pythontypes. This can be disabled with the directive annotation_typing=False
.Note that most complex PEP-484 style annotations are currently ignored. This willchange in future releases. (Github issue #1850) - Extension types (also in pure Python mode) can implement the normal special methods
eq
, lt
etc. for comparisons instead of the low-level richcmp
method. (Github issue #690) - New decorator
@cython.exceptval(x=None, check=False)
that makes the signaturedeclarations except x
, except? x
and except *
available to pure Pythoncode. Original patch by Antonio Cuni. (Github issue #1653) - Signature annotations are now included in the signature docstring generated bythe
embedsignature
directive. Patch by Lisandro Dalcin (Github issue #1781). - The gdb support for Python code (
libpython.py
) was updated to the latestversion in CPython 3.7 (git rev 5fe59f8). - The compiler tries to find a usable exception return value for cdef functionswith
except *
if the returned type allows it. Note that this feature is subjectto safety limitations, so it is still better to provide an explicit declaration. - C functions can be assigned to function pointers with a compatible exceptiondeclaration, not only with exact matches. A side-effect is that certain compatiblesignature overrides are now allowed and some more mismatches of exception signaturesare now detected and rejected as errors that were not detected before.
- The IPython/Jupyter magic integration has a new option
%%cython —pgo
for profileguided optimisation. It compiles the cell with PGO settings for the C compiler,executes it to generate a runtime profile, and then compiles it again using thatprofile for C compiler optimisation. Currently only tested with gcc. len(memoryview)
can be used in nogil sections to get the size of thefirst dimension of a memory view (shape[0]
). (Github issue #1733)- C++ classes can now contain (properly refcounted) Python objects.
- NumPy dtype subarrays are now accessible through the C-API.Patch by Gerald Dalley (Github issue #245).
- Resolves several issues with PyPy and uses faster async slots in PyPy3.Patch by Ronan Lamy (Github issues #1871, #1878).
Bugs fixed
- Extension types that were cimported from other Cython modules could disagreeabout the order of fused cdef methods in their call table. This could leadto wrong methods being called and potentially also crashes. The fix requiredchanges to the ordering of fused methods in the call table, which may breakexisting compiled modules that call fused cdef methods across module boundaries,if these methods were implemented in a different order than they were declaredin the corresponding .pxd file. (Github issue #1873)
- The exception state handling in generators and coroutines could lead toexceptions in the caller being lost if an exception was raised and handledinside of the coroutine when yielding. (Github issue #1731)
- Loops over
range(enum)
were not converted into C for-loops. Note that itis still recommended to use an explicit cast to a C integer type in this case. - Error positions of names (e.g. variables) were incorrectly reported after thename and not at the beginning of the name.
- Compile time
DEF
assignments were evaluated even when they occur inside offalsy IF
blocks. (Github issue #1796) - Disabling the line tracing from a trace function could fail.Original patch by Dmitry Trofimov. (Github issue #1769)
- Several issues with the Pythran integration were resolved.
- abs(signed int) now returns a signed rather than unsigned int.(Github issue #1837)
- Reading
frame.f_locals
of a Cython function (e.g. from a debugger or profilercould modify the module globals. (Github issue #1836) - Buffer type mismatches in the NumPy buffer support could leak a reference to thebuffer owner.
- Using the “is_f_contig” and “is_c_contig” memoryview methods together could leaveone of them undeclared. (Github issue #1872)
- Compilation failed if the for-in-range loop target was not a variable but a morecomplex expression, e.g. an item assignment. (Github issue #1831)
- Compile time evaluations of (partially) constant f-strings could show incorrectresults.
- Escape sequences in raw f-strings (
fr'…'
) were resolved instead of passingthem through as expected. - Some ref-counting issues in buffer error handling have been resolved.
Other changes
- Type declarations in signature annotations are now parsed according toPEP 484typing. Only Cython types (e.g.
cython.int
) and Python builtin types arecurrently considered as type declarations. Everything else is ignored, but thiswill change in a future Cython release.(Github issue #1672) - The directive
annotation_typing
is now True
by default, which enablesparsing type declarations from annotations. - This release no longer supports Python 3.2.