After five years, Cython 3.0 is officially released

After nearly five long years, Cython 3.0 is officially released.

According to the announcement , "Cython 3.0 is better than any other Cython version before it in every way. It is more Pythonic, better integrated with C and C++, supports more Python implementations and configurations, and provides many great new language features. Faster, safer, and easier to use. It's simply better."

New language features include:

  • Python 3 default syntax and semantics
  • Cython type annotations in pure Python code
  • Automatic NumPy ufunc generation
  • Fast @dataclass and @total_ordering extension types
  • Safe exception propagation in C functions by default
  • Unicode identifiers in Cython code

Cython 3 cleans up and modernizes Cython in many ways. It dropped support for the long-deprecated Python 2, added support for newer Python features (up to Python 3.12), and expanded the use of pure Python mode ( pure python ). "In short, this allows a wider range of Python code to be compiled into optimized C code."

According to the introduction, the pure Python mode allows Python developers to use existing Python linting and code analysis tools on Cython. Cython has historically used its own unique syntax, a mix of Python syntax and C type declaration syntax, which has made Cython difficult to troubleshoot with Python tools. Over time, Cython started to provide an alternative syntax that is fully compatible with traditional Python syntax, called pure Python mode. Most Cython functions are now displayed in pure Python mode, including functions that call external C libraries.

Another major improvement is NumPy support. Cython 3 adds the ability to write NumPy ufuncs directly in Cython, so that simple numerical functions written in Cython can be quickly and easily applied to the entire contents of NumPy data structures.

Cython's internals have also been redesigned to better match the changing internals of Python. For example, Python's new "limited API" exposes a guaranteed stable subset of the Python API, specifically for the types of work that Cython often hooks the Python interpreter . Cython 3 has initially supported limited API, and this support is still increasing. In the long run, InfoWorld notes, this means that a Cython extension module built for one version of Python can run in a future version of Python without recompilation.

More details can be found in the official announcement .

Guess you like

Origin www.oschina.net/news/250365/cython-3-0-released