New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cython should emulate the Py3 print() function in Py2 < 2.6 #628
Comments
@dagss changed cc to There are problems with using using transforms for this. a) If you want to do it prior to scope analysis, code like this likely won't work properly:
b) So, it should be done after scope analysis. But then the scope analysis won't find the entry in the first place. |
scoder changed description from 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+. to 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 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+. |
scoder commented The future import was implemented for ticket http://trac.cython.org/ticket/516, so this ticket is reduced to providing a fallback implementation for Python versions before 2.6. |
@bhy changed cc from I'm trying to insert a print function before the actual code, like this:
but the problem is def in control structure cannot work properly yet (http://trac.cython.org/ticket/87). |
scoder changed resolution to Waiting long enough can help, Cython is Py2.6+ now. |
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+.
Migrated from http://trac.cython.org/ticket/69
The text was updated successfully, but these errors were encountered: