Cython should emulate the Py3 print() function in Py2 < 2.6
|Reported by:||Stefan Behnel||Owned by:||somebody|
|Cc:||stefan_ml@…, dagss@…, biahaoyu@…|
Description (last modified by scoder)
Given the whitespace semantics of the Py2 print statement which are hard to emulate in Py3, it would be nice if Cython could provide the print() function in a portable way, depending on the "print_function" future import. Code that requires specific semantics could then express them in a portable way using the print function.
This is not trivial, as it would require different code in Py2 versions before 2.6. Py2.6 and later should delegate directly to the normal __builtins__.print function, wheres earlier Py2 versions must delegate to an equivalent function provided by the module itself. Python's print() function uses an arbitrary number of positional arguments and a number of keyword-only arguments. This cannot currently be expressed using the normal builtins declaration mechanism. On the other hand, it is rather trivial to implement the print() function in pure Cython.
If emulation also under Py2.6+ is acceptable, we could inline the print function call using a transform. However, maybe we could just provide a Cython-implemented builtin-function as a private Python function in the module. In this case, some special casing could take care of replacing the function by the real builtin in Py2.6+.