imports and py3 compatibility

36 views
Skip to first unread message

fchap...@gmail.com

unread,
Aug 15, 2016, 6:01:30 AM8/15/16
to cython-users
Hello,

I have a question about imports in cython and python2/python3 compatibility.

I am working on sagemath, with a large number of cython files.

To ensure compatibility with both py2 and py3, is it necessary in cython files (just as in python files) to add

from __future__ import absolute_import

and to change the imports to the python3 syntax ?

And what about the cimports ?

Is there any tool available to do this cleanly for me ? Something like futurize ?

Frederic

Hai Nguyen

unread,
Aug 15, 2016, 11:22:36 AM8/15/16
to cython...@googlegroups.com


On Monday, August 15, 2016, <fchap...@gmail.com> wrote:
Hello,

I have a question about imports in cython and python2/python3 compatibility.

I am working on sagemath, with a large number of cython files.

To ensure compatibility with both py2 and py3, is it necessary in cython files (just as in python files) to add

from __future__ import absolute_import

and to change the imports to the python3 syntax ?

And what about the cimports ?


 Did you get trouble using cimport? I am not clear if this relates to py2 py3 issues. Hai


Is there any tool available to do this cleanly for me ? Something like futurize ?

Frederic

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Bradshaw

unread,
Aug 16, 2016, 12:21:14 AM8/16/16
to cython...@googlegroups.com
On Mon, Aug 15, 2016 at 2:29 AM, <fchap...@gmail.com> wrote:
> Hello,
>
> I have a question about imports in cython and python2/python3 compatibility.
>
> I am working on sagemath, with a large number of cython files.
>
> To ensure compatibility with both py2 and py3, is it necessary in cython
> files (just as in python files) to add
>
> from __future__ import absolute_import
>
> and to change the imports to the python3 syntax ?

By default, Cython assumes code is Python 2 but produces extensions
compatible with Python 3. Somewhat in jest, Cython has been called the
easiest way to port Python 2 code to Python 3--just compile it.

Cython does support "from __future__ import absolute_import" and if
you use this, you do have to change the imports to be Python 3
compatible.

> And what about the cimports ?

Exactly the same as imports.

> Is there any tool available to do this cleanly for me ? Something like
> futurize ?

Not that I know of, but for just fixing [c]imports a simple script
probably wouldn't be too hard to put together.
Reply all
Reply to author
Forward
0 new messages