__kwdefaults__
special attribute of fused functions. (Github issue #1470)
prange()
loops appear inside of with-statements. (Github issue #2780)
ZeroDivisionError
. (Github issue #2820)
sigismember()
in
libc.signal
was corrected. (Github issue #2756)
try
-statements generated invalid C code. (Github issue #2274)
warn.undeclared
directive, Cython’s own code generated warnings that are now fixed. Patch by Nicolas Pauss. (Github issue #2685)
PyBUF_ND
flag to be set. Patch by John Kirkham. (Github issue #2716)
operator[]
could fail to compile. (Github issue #2671)
from
...
cimport
...
constructs were not correctly considered when searching modified dependencies in
cythonize()
to decide whether to recompile a module. Patch by Kryštof Pilnáček. (Github issue #2638)
cpython.array
declarations was corrected. Patch by John Kirkham. (Github issue #2712)
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 #1965)
@cython.nogil
is supported as a C-function decorator in Python code. (Github issue #2557)
with
gil
块。
cython.inline()
supports a direct
language_level
keyword argument that was previously only available via a directive.
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.
.cc
and
.cxx
. (Github issue #2266)
cythonize
command accepts compile time variable values (as set by
DEF
) through the new
-E
option. Patch by Jerome Kieffer. (Github issue #2315)
pyximport
can import from namespace packages. Patch by Prakhar Goel. (Github issue #2294)
pylifecycle
C-API functions were added in a new .pxd file
cpython.pylifecycle
.
%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.
CYTHON_HEX_VERSION
to access Cython’s version in the same style as
PY_HEX_VERSION
.
libc.math
are now declared as
const
to simplify their handling.
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 #2627)
__rmod__()
method if the right side is a string subclass that implements it. (Python issue 28598)
language_level=3
did not apply to the first token in the source file. (Github issue #2230)
@cfunc
functions. (Github issue #459)
const
types were not excluded from star-import assignments which could lead to invalid C code. (Github issue #2621)
set_array_base()
and
get_array_base()
were adapted to the current numpy C-API recommendations. Patch by Matti Picus. (Github issue #2528)
c_string_encoding
directive appeared within the first two lines. (Github issue #2632)
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.
optimize("Os")
was replaced by the similar attribute
cold
to reduce the code impact of the module init functions. (Github issue #2494)
tp_clear()
in a subtype of an
@no_gc_clear
extension type generated an invalid C function call to the (non-existent) base type implementation. (Github issue #2309)
UnicodeEncodeError
in Py2 when
%s
formatting is optimised for unicode strings. (Github issue #2276)
abs()
is faster for Python long objects.
front()
and
end()
were added to the declaration of
libcpp.string
. Patch by Alex Huszagh. (Github issue #2123)
reserve()
and
bucket_count()
are declared for
libcpp.unordered_map
. Patch by Valentin Valls. (Github issue #2168)
switch
statement generation failed to apply recursively to the body of converted if-statements.
NULL
was sometimes rejected as exception return value when the returned type is a fused pointer type. Patch by Callie LeFave. (Github issue #2177)
PyFrozenSet_New()
was accidentally used in PyPy where it is missing from the C-API.
const
with
ctypedef
. (Github issue #2148)
nogil
. (Github issue #2157)
basestring
(bytes or unicode) as result type in some cases where
bytes
would have been safe to infer. (Github issue #2153)
None
was accidentally disallowed as typed return value of
dict.pop()
. (Github issue #2152)
object
, and the other bases must
not
be cdef classes.)
const
modifier can be applied to memoryview declarations to allow read-only buffers as input. (Github issues #1605, #1869)
cdef
extern
block is copied verbatimly into the generated file. Patch by Jeroen Demeyer. (Github issue #1915)
@cython.iterable_coroutine
changes its type at compile time to make it iterable. While this is not strictly in line with PEP-492, it improves the interoperability with old-style coroutines that use
yield
from
而不是
await
.
Py_tss_t
type defined in PEP-539 and automatically initialises variables declared with that type to
Py_tss_NEEDS_INIT
, a value which cannot be used outside of static assignments.
.remove()
and
.discard()
are optimised. Patch by Antoine Pitrou. (Github issue #2042)
dict.pop()
is optimised. Original patch by Antoine Pitrou. (Github issue #2047)
alist.extend([a,b,c])
is optimised into sequential
list.append()
calls for short literal sequences.
bytearray
operations have been optimised similar to
bytes
.
view[i][j]
is now optimised into
view[i,
j]
.
cython.*
types can now be mixed with type declarations in Cython syntax.
libc/signal.pxd
. Patch by Jeroen Demeyer. (Github issue #1914)
CYTHON_NO_PYINIT_EXPORT
will prevent the module init function from being exported as symbol, e.g. when linking modules statically in an embedding setup. Patch by AraHaan. (Github issue #1944)
Extension()
that is compiled via
cythonize()
, it was previously ignored and replaced by the source file name. It can now be used to override the target module name, e.g. for compiling prefixed accelerator modules from Python files. (Github issue #2038)
num_threads
parameter of parallel sections were not sufficiently validated and could lead to invalid C code. (Github issue #1957)
__richcmp__()
method was corrected to recognise the type of the first argument as
self
. It was previously treated as plain object, but CPython actually guarantees that it always has the correct type. Note: this can change the semantics of user code that previously relied on
self
being untyped.
unordered_map
were corrected. Patch by Michael Schatzow. (Github issue #1484)
deque
and
vector
were corrected. Patch by Alex Huszagh. (Github issue #1870)
string
declarations were corrected, together with the coercion behaviour of string literals into C++ strings. (Github issue #2132)
libc.limits
were corrected. Patch by Jeroen Demeyer. (Github issue #2016)
@cython.final
was not accepted on Python classes with an
@cython.cclass
decorator. (Github issue #2040)
PyInstanceMethod
wrappers for methods in Python 3. Patch by Jeroen Demeyer. (Github issue #2105)
bytearray
type could not be used as base type of cdef classes. (Github issue #2106)
@cython.locals(x="ExtType")
failed to find the named type. (Github issue #1962)
PyThreadState
in CPython 3.7.
PyWeakref_GetObject()
API declaration. Patch by Jeroen Demeyer (Github issue #1975).
__eq__
,
__lt__
etc. in extension types did not type their first argument as the type of the class but
object
. (Github issue #1935)
std::unordered_map.erase()
was declared with an incorrect
void
return type in
libcpp.unordered_map
. (Github issue #1484)
fallthrough
attribute before C++11 and similar issue in clang. (Github issue #1930)
--verbose
that shows details about the distutils invocation. Patch by Boris Filippov (Github issue #1881).
unique_ptr
.
annotation_typing=False
.
__file__
and
__path__
correctly available to module level code and improves the support for module-level relative imports. (Github issues #1715, #1753, #1035)
cython.int
) are evaluated as C type declarations and everything else as Python types. This can be disabled with the directive
annotation_typing=False
. Note that most complex PEP-484 style annotations are currently ignored. This will change in future releases. (Github issue #1850)
__eq__
,
__lt__
etc. for comparisons instead of the low-level
__richcmp__
method. (Github issue #690)
@cython.exceptval(x=None,
check=False)
that makes the signature declarations
except
x
,
except?
x
and
except
*
available to pure Python code. Original patch by Antonio Cuni. (Github issue #1653)
embedsignature
directive. Patch by Lisandro Dalcin (Github issue #1781).
libpython.py
) was updated to the latest version in CPython 3.7 (git rev 5fe59f8).
except
*
if the returned type allows it. Note that this feature is subject to safety limitations, so it is still better to provide an explicit declaration.
%%cython
--pgo
for profile guided 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 that profile for C compiler optimisation. Currently only tested with gcc.
len(memoryview)
can be used in nogil sections to get the size of the first dimension of a memory view (
shape[0]
). (Github issue #1733)
range(enum)
were not converted into C for-loops. Note that it is still recommended to use an explicit cast to a C integer type in this case.
DEF
assignments were evaluated even when they occur inside of falsy
IF
blocks. (Github issue #1796)
frame.f_locals
of a Cython function (e.g. from a debugger or profiler could modify the module globals. (Github issue #1836)
fr'...'
) were resolved instead of passing them through as expected.
cython.int
) and Python builtin types are currently considered as type declarations. Everything else is ignored, but this will change in a future Cython release. (Github issue #1672)
annotation_typing
现为
True
by default, which enables parsing type declarations from annotations.
cython.view.array
was missing
.__len__()
.
.pxd
override for their
__releasebuffer__
slot (e.g. as provided by Cython for the Python
array.array
type) could leak a reference to the buffer owner on release, thus not freeing the memory. (Github issue #1638)
const
integer variables could generate invalid code. (Github issue #1798)
result
or
PickleError
generated invalid unpickling code. Patch by Jason Madden (Github issue #1786).
.py
files. Patch by Guro Bokum (Github issue #1784).
_PyCFunctionFast()
auto_pickle
指令。
__all__
variable and ignores names with leading-underscore (like
import
*
does). Patch by Syrtis Major (Github issue #1625).
abs()
is optimised for C complex numbers. Patch by da-woods (Github issue #1648).
import
cython_runtime;
cython_runtime.cline_in_traceback=True
. The default has been changed to False.
Py_UCS4
or
Py_UNICODE
used the integer value instead of the Unicode string value. Code that relied on the previous behaviour now triggers a warning that can be disabled by applying an explicit cast. (Github issue #1602)
iter*
methods failed in PyPy3. Patch by Armin Rigo (Github issue #1631).
unraisable_tracebacks
option now defaults to
True
.
isinstance(o,
Exception)
(Github issue #1496).
cython.view.array
missing utility code in some cases (Github issue #1502).
Cython.Distutils.build_ext
has been reverted, temporarily, to be
old_build_ext
to give projects time to migrate. The new build_ext is available as
new_build_ext
.
cdef
dict
__dict__
is declared in the class. Patch by empyrical.
cython.no_gc
to fully disable GC for a cdef class. Patch by Claudio Freire.
locals()
. Patch by da-woods.
libc/math.pxd
提供
e
and
pi
as alias constants to simplify usage as a drop-in replacement for Python’s math module.
typeid
运算符。
libc.math
and
numpy.pxd
were incorrect. Patch by Michael Seifert.
Cython.Distutils.build_ext
has now been updated to use cythonize which properly handles dependencies. The old extension can still be found in
Cython.Distutils.old_build_ext
and is now deprecated.
directive_defaults
is no longer available in
Cython.Compiler.Options
,使用
get_directive_defaults()
代替。
__aiter__()
method of asynchronous iterators to be a simple
def
method instead of an
async
def
方法。
__module__
special attribute.
std::complex
values failed to auto-convert from and to Python complex objects.
distutils
compiler option do not require values anymore. Patch by Ian Henriksen.
emit_code_comments=False
.
unicode()
,
xrange()
,
reduce()
and
long
are now also available in compile time
DEF
expressions when compiling with Py3.
str
expressions (
DEF
) now behave in a more useful way by turning into Unicode strings when compiling under Python 3. This allows using them as intermediate values in expressions. Previously, they always evaluated to bytes objects.
isinf()
declarations in
libc/math.pxd
and
numpy/math.pxd
now reflect the actual tristate
int
return value instead of using
bint
.
dict(...).items()
failed to get optimised when dict arguments included keyword arguments.
None
.
all(genexpr)
/
any(genexpr)
calls could warn about unused code. This fixes ticket 876.
Coroutine
and
生成器
ABCs in the
backports_abc
module if it can be imported. This fixes ticket 870.
ino_t
in
posix.types
was not declared as
unsigned
.
libcpp/memory.pxd
were missing
operator!()
. Patch by Leo Razoumov.
from
xyz
import
*
and global C struct/union/array variables could fail to compile due to missing helper functions. This fixes ticket 851.
cr_yieldfrom
renamed to
cr_await
to match CPython.
yield
in signature annotations and default argument values. Both are forbidden now.
finally
子句。
nogil
functions/sections and module init code.
生成器
and
Coroutine
ABCs in the
collections
or
collections.abc
stdlib module at import time to enable interoperability with code that needs to detect and process Python generators/coroutines. These ABCs were added in CPython 3.5 and are available for older Python versions through the
backports_abc
module on PyPI. See
https://bugs.python.org/issue24018
all()
,
any()
,
dict()
,
list()
,
set()
,
sorted()
and
unicode.join()
avoid the generator iteration overhead by inlining a part of their functionality into the for-loop.
PyTypeObject
declaration in
cpython.object
was extended.
type
type is now declared as PyTypeObject in source, allowing for extern functions taking type parameters to have the correct C signatures. Note that this might break code that uses
type
just for passing around Python types in typed variables. Removing the type declaration provides a backwards compatible fix.
wraparound()
and
boundscheck()
are available as no-ops in pure Python mode.
NULL
is allowed as default argument when embedding signatures. This fixes ticket 843.
--embed
, the internal module name is changed to
__main__
to allow arbitrary program names, including those that would be invalid for modules. Note that this prevents reuse of the generated C code as an importable module.
cpdef
void
methods are now permitted.
abs(cint)
could fail to compile in MSVC and used sub-optimal code in C++. Patch by David Vierra, original patch by Michael Enßlin.
foo.pyx
, the directories in
sys.path
are no longer searched when looking for
foo.pxd
. Patch by Jeroen Demeyer.
cdef
api
declarations.
jedi-typer.py
(in
Tools/
) was extended and renamed to
jedityper.py
(to make it importable) and now works with and requires Jedi 0.9. Patch by Tzer-jen Wei.
void
failed to compile.
const
C++ references in intermediate parts of longer expressions could fail to compile.
reversed(range())
is optimised in the same way as
range()
. Patch by Favian Contreras.
cythonize()
is now an error to more easily detect accidental typos.
logaddexp
family of functions in
numpy.math
now has correct declarations.
_
is no longer considered a cacheable builtin as it could interfere with gettext.
str
generated incomplete code that failed to compile.
resize_smart()
in
cpython.array
was broken.
libcpp.cast
are now declared as
nogil
.
cythonize
option
-a
to generate the annotated HTML source view.
cpython.unicode
被添加。
language='c++'
into cythonize() globally enables C++ mode for all modules that were not passed as Extension objects (i.e. only source files and file patterns).
Py_hash_t
is a known type (used in CPython for hash values).
PySlice_*()
C-API functions are available from the
cpython.slice
模块。
std::string
to Python byte strings failed when auto-decoding was enabled.
cythonize.py
script was not installed on MS-Windows.
char*
from a temporary Python string object is safer in more cases and can be done inside of non-trivial expressions, including arguments of a function call. A compile time error is raised only when such a pointer is assigned to a variable and would thus exceed the lifetime of the string itself.
__name__
and
__qualname__
that provide the plain/qualified name of the generator function (following CPython 3.5). See
http://bugs.python.org/issue21205
inline
function modifier is available as a decorator
@cython.inline
in pure mode.
annotation_typing=True
.
use_switch
(defaults to True) to optionally disable the optimization of chained if statement to C switch statements.
libcpp.cast
and C++ heap data structure operations in
libcpp.algorithm
.
posix.*
were extended to cover more of the POSIX API. Patches by Lars Buitinck and Mark Peek.
slice()
are translated to a straight C-API call.
char*
from an indexed Python string generated unsafe reference counting code.
cdef
func(floating[:]
a,
floating[:]
b)
). This is considered the expected behaviour by most users and was previously inconsistent with other structured types like C arrays. Code that really wants all type combinations can create the same fused memoryview type under different names and use those in the signature to make it clear which types are independent.
obj.pop(x)
truncated large C integer values of x to
Py_ssize_t
.
__init__.pyc
is recognised as marking a package directory (in addition to .py, .pyx and .pxd).
cython-mode.el
for Emacs no longer incorrectly highlights keywords found as part of longer names.
from
cython.submodule
cimport
name
.
dir()
was not guaranteed to return a sorted list.
[].append.__name__
) could fail to compile.
c_string_encoding=ascii
failed in Py3.3.
__slots__
.
cython.array
objects was accidentally omitted in Py3.
isspace()
could not be resolved by clang.
yield
is supported in
finally
子句。
bytearray
has become a known type and supports coercion from and to C strings. Indexing, slicing and decoding is optimised. Note that this may have an impact on existing code due to type inference.
cdef
basestring
stringvar
and function arguments typed as
basestring
is now meaningful and allows assigning exactly
str
and
unicode
objects, but no subtypes of these types.
__debug__
builtin.
bin/cythonize
provides a command line frontend to the cythonize() compilation function (including distutils build).
@cython.no_gc_clear
prevents objects from being cleared during cyclic garbage collection, thus making sure that object attributes are kept alive until deallocation.
__init__.py
files) now works, starting with Python 3.3.
unraisable_tracebacks
directive added to control printing of tracebacks of unraisable exceptions.
set.add(a_tuple)
and
set.discard(a_tuple)
failed with a TypeError in Py2.4.
__qualname__
was incorrect for nested classes and inner classes/functions declared as
global
.
metaclass
keyword argument. In Py2 compilation mode, a
__metaclass__
entry in the class dict will still take precedence if not using Py3 metaclass syntax, but only
after
creating the class dict (which may have been done by a metaclass of a base class, see PEP 3115). It is generally recommended to use the explicit Py3 syntax to define metaclasses for Python types at compile time.
__metaclass__
class dict entry are ignored.
tp_finalize()
for safer cleanup instead of
tp_del()
.
PyBuffer_FillInfo()
and some missing bits in
libc.math
.
type
used the wrong base type struct at the C level.
bint
arguments now appear as type
bool
.
wraparound
handling. This helps with fixing invalid code that might fail in the face of future compiler optimisations.
isinstance(X,
type)
failed to get optimised into a call to
PyType_Check()
, as done for other builtin types.
from
datetime
cimport
*
was removed from the “cpython” declaration package. This means that the “datetime” declarations (added in 0.19) are no longer available directly from the “cpython” namespace, but only from “cpython.datetime”. This is the correct way of doing it because the declarations refer to a standard library module, not the core CPython C-API itself.
memoryview
type name no longer shows up in the module dict of modules that use memory views. This fixes trac ticket 775.
restrict
could accidentally be seen by the GNU C++ compiler. It is now specially handled for both GCC and MSVC.
c_string_type
and
c_string_encoding
to more easily and automatically convert between C strings and the different Python string types.
Py_TPFLAGS_HAVE_VERSION_TAG
is enabled by default on extension types and can be disabled using the
type_version_tag
compiler directive.
__annotations__
attribute (PEP 3107).
Py_UNICODE*
coerces from and to Python unicode strings. This is helpful when talking to Windows APIs, which use compatible wchar_t arrays for strings. Note that the
Py_UNICODE
type is otherwise deprecated as of CPython 3.3.
isinstance(obj,
basestring)
is optimised. In Python 3 it only tests for instances of
str
(i.e. Py2
unicode
).
basestring
builtin is mapped to
str
(i.e. Py2
unicode
) when compiling the generated C code under Python 3.
@cython.freelist(N)
creates a static freelist of N instances for an extension type, thus avoiding the costly allocation step if possible. This can speed up object instantiation by 20-30% in suitable scenarios. Note that freelists are currently only supported for base types, not for types that inherit from others.
Type.__new__(Type)
idiom has gained support for passing arguments. It is also a bit faster for types defined inside of the module.
.iter*()
and
.view*()
(requires Python 2.7) are automatically mapped to the equivalent keys/values/items methods in Python 3 for typed dictionaries.
raise
Exception()
from
None
suppresses the exception context in Py3.3.
exec(tuple)
syntax is supported in Py2 code.
getitem
protocol is used instead of the
getslice
protocol (especially in Python 3), i.e.
None
values for missing bounds instead of
[0,maxsize]
. It is also a bit faster in some cases, e.g. for constant bounds. This fixes trac ticket 636.
TypeError
在运行时。
__defaults__
attribute was not writable for Cython implemented functions.
__defaults__
而不是
__kwdefaults__
(which was not implemented). Both are available for Cython implemented functions now, as specified in Python 3.x.
yield
works inside of
with
gil
sections. It previously lead to a crash. This fixes trac ticket 803.
*args
) crashed when being called. This fixes trac ticket 804.
dir()
without arguments previously returned an unsorted list, which now gets sorted as expected.
dict.items()
,
dict.keys()
and
dict.values()
no longer return lists in Python 3.
except-as
clause now deletes the exception in Python 3 mode.
frexp()
and
ldexp()
in
math.pxd
were incorrect.
overflowcheck
which raises an OverflowException when arithmetic with C ints overflow. This has a modest performance penalty, but is much faster than using Python ints.
py_bytes_string.decode(...)
is optimised.
const
declarations are supported in the language.
cdef
__weakref__
attribute) generated incorrect deallocation code.
cythonize()
gained a best effort compile mode that can be used to simply ignore .py files that fail to compile.
The availability of type inference by default means that Cython will also infer the type of pointers on assignments. Previously, code like this:
cdef char* s = ... untyped_variable = s
would convert the char* to a Python bytes string and assign that. This is no longer the case and no coercion will happen in the example above. The correct way of doing this is through an explicit cast or by typing the target variable, i.e.
cdef char* s = ... untyped_variable1 = <bytes>s untyped_variable2 = <object>s cdef object py_object = s cdef bytes bytes_string = s
bool is no longer a valid type name by default. The problem is that it’s not clear whether bool should refer to the Python type or the C++ type, and expecting one and finding the other has already led to several hard-to-find bugs. Both types are available for importing: you can use from cpython cimport bool for the Python bool type, and from libcpp cimport bool for the C++ type. bool is still a valid object by default, so one can still write bool(x).
__getsegcount__
is now correctly typed to take a
Py_size_t*
rather than an
int*
.
There’s now native complex floating point support! C99 complex will be used if complex.h is included, otherwise explicit complex arithmetic working on all C compilers is used. [Robert Bradshaw]
cdef double complex a = 1 + 0.3j cdef np.ndarray[np.complex128_t, ndim=2] arr = \ np.zeros(10, np.complex128)
Cython can now generate a main()-method for embedding of the Python interpreter into an executable (see #289) [Robert Bradshaw]
@wraparound directive (another way to disable arr[idx] for negative idx) [Dag Sverre Seljebotn]
Correct support for NumPy record dtypes with different alignments, and “cdef packed struct” support [Dag Sverre Seljebotn]
@callspec directive, allowing custom calling convention macros [Lisandro Dalcin]