Repository navigation
use six.moves versions for map/range/zip (when used) - #5259
Conversation
|
Are we sure we want to do all? I think it does slow down things slightly and to me the benefits are not obvious. I do think it is good to get rid of ... ... ... well, actually, I should check before I write: on python3 while it is Still, I think I slightly prefer to keep the boilerplate to the |
|
@mhvk Thank you for the fast answer. Regarding the rationale: The They are all imported from the standard library so the import overhead should be negligable but I only added them where they are actually used. However I don't feel strong about it so if you think that's not really necessary I can alter/close the PR again. |
| from .common import setup_function, teardown_function | ||
| from ....tests.helper import pytest | ||
| from ....extern.six.moves import cStringIO | ||
| from ....extern.six.moves import range, cStringIO as StringIO |
There was a problem hiding this comment.
Why is there a need to rename cStringIO? Won't that just be adding to the confusion?
There was a problem hiding this comment.
Because it's now called StringIO. Like xrange, izip and imap it's a name that isn't used anymore in python3.
|
Given the plan to completely drop Python 2 support by v3 (see APE10), does this just add more stuff to undo in the near future? EDIT: Corrected link. |
|
@MSeifert04 , haha, yes... On Linux, there are two different clipboards and my click pulled the wrong one. It is corrected. Good catch! |
|
We just have to think about if this is worth all the undoing a year from now. This is not really fixing any bug, right? So, really, no gain, but a lot of extra work later. Please correct me if I am wrong. |
Right
I think it probably won't have noticible gain for python2 and for python3 there is no gain at all. However for several modules there is already a |
|
I totally forgot: I removes a lot of unnecessary whitespaces! That shaves some bytes off the package 😅 |
|
Okay, all good points. Since the work is already done... why not? 👍 |
|
I guess overall the work is minimized any time python2-only names are no longer used, and if we go to a state where all we need to do to make it python3-only is to remove lines importing from I'm still not completely sold on just adding imports where things worked fine with python2 and python3 using exactly the same code while effectively doing something slightly different, but on the other hand like @pllim I can see the advantage of minimizing those cases. So, overall, I'm happy to merge this, but just in case let me ping @astrofrog as the one who has thought the move to python3 through most. |
| import numpy as np | ||
|
|
||
| from astropy.table import Table, Column | ||
| from astropy.extern.six.moves import range |
There was a problem hiding this comment.
I wasn't sure: Should these be relative imports?
There was a problem hiding this comment.
Huh, I don't see why they can't be relative.
There was a problem hiding this comment.
Agreed they should be relative.
|
OK, I think enough time for second thought has passed, so I'll merge! Thanks, @MSeifert04! |
This PR adds from
extern.six.movesat all places wheremap,ziporrangeare used.Originally I only wanted to replace them where python2 names or the
try ... except ...was still used, i.e.from six.moves import xrangeorizip. But then I thought it probably wouldn't hurt to use the generator versions.This PR also removes some trailing whitespaces or rows containing only whitespaces. (that was accidental because my editor is setup to remove them "on saving", but that doesn't hurt either, right?)