how to check zip, map, range, print for Python3

71 views
Skip to first unread message

Frédéric Chapoton

unread,
Jan 26, 2017, 3:02:07 PM1/26/17
to sage-devel
Hello,

your help is required for some Python3-related question, please.

I would like to have a branch which activates the future behaviour of zip (for example, but range or map are also candidates) both in code and doctests.

Here is my tentative for zip, that only change zip behaviour in the doc:


as you can see by building the branch and testing the added file.

Please, tell me how to  change the zip behaviour in the code. Or just change the branch if you know how.

Frederic


David Roe

unread,
Jan 26, 2017, 3:30:08 PM1/26/17
to sage-devel
Don't you just need to add
from six.moves import zip
at the top of every file where zip is used?
David

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

Frédéric Chapoton

unread,
Jan 26, 2017, 3:47:52 PM1/26/17
to sage-devel, roed...@gmail.com
hmmmm, I was hoping for a simpler solution, like putting this in a single well-chosen file...

Frederic


Le jeudi 26 janvier 2017 21:30:08 UTC+1, David Roe a écrit :
Don't you just need to add
from six.moves import zip
at the top of every file where zip is used?
David
On Thu, Jan 26, 2017 at 3:02 PM, Frédéric Chapoton <fchap...@gmail.com> wrote:
Hello,

your help is required for some Python3-related question, please.

I would like to have a branch which activates the future behaviour of zip (for example, but range or map are also candidates) both in code and doctests.

Here is my tentative for zip, that only change zip behaviour in the doc:


as you can see by building the branch and testing the added file.

Please, tell me how to  change the zip behaviour in the code. Or just change the branch if you know how.

Frederic


--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.

David Roe

unread,
Jan 26, 2017, 6:48:21 PM1/26/17
to Frédéric Chapoton, sage-devel
On Thu, Jan 26, 2017 at 3:47 PM, Frédéric Chapoton <fchap...@gmail.com> wrote:
hmmmm, I was hoping for a simpler solution, like putting this in a single well-chosen file...

I don't see how to do that, just because of the way Python works (though I'd be happy to hear a trick to do this!).  When we import code from those Python files, the evaluation is done within the context of that file and the local imports there.  zip is a built in function, so you need to replace it in the local namespace....
David
 

Nils Bruin

unread,
Jan 26, 2017, 8:13:49 PM1/26/17
to sage-devel
On Thursday, January 26, 2017 at 12:02:07 PM UTC-8, Frédéric Chapoton wrote:

Please, tell me how to  change the zip behaviour in the code. Or just change the branch if you know how.

If I understand correctly, part of your question is "how do I get zip to behave line Py3 in the doctests".

It's a bit of a puzzle, but somewhere in sage.doctest.control there is code that assembles the doctests into a file to be fed to python. In principle, it should be possible to insert a "from future_builtins import zip" into those files.

David Roe

unread,
Jan 26, 2017, 8:18:14 PM1/26/17
to sage-devel
But that won't help when the code is actually being run, not in doctests.  I agree that the doctesting behavior can be changed (as a guess, something around line 2122 of sage/doctest/forker.py).
David

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages