-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
2to3: Apply imports
fixer.
#3191
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
Conversation
The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes numpy#3180.
if sys.version_info[0] >= 3: | ||
import pickle | ||
else: | ||
import cPickle as pickle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Python likes sentence punctuation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- . And I thought I fixed that... must have fat fingered something along the way.
I'm wary about the doc-related code changes in general -- these are potential behavioural changes that travis doesn't test, right? Do we know the docs still build with this PR? |
Yeah, me to. I was going to test first but got hasty. I'll give it a shot. |
There was a stray period at the end of an import statement in `doc/cdoc/numpyfilter.py`. Looks like a cut and paste error that was fixed elsewhere but escaped there because the module isn't tested. A search shows that this was the only spot in which the error was still present.
OK, I installed sphinxext from the repository and did |
TLC definitely needed. The problem is that Sphinx and the autodoc extension go out of their way to prevent you from seeing where the warnings come from. Fixing that first would be much more useful than trying to work through all the warnings now. |
I have a suspicion that a lot of them are due to file names of the form xxx.yyy.zzz.rst and the extension stripping. |
Hmm, well, I guess this is good then? If we end up breaking scipy's docs or something then I'm sure we'll hear about it sooner or later :-) @charris, merge if you think it's ready? |
OK, in it goes. The next one is simpler ;) |
The
imports
fixer deals with the standard packages that have beenrenamed, removed, or methods that have moved.
cPickle
-- removed, usepickle
commands
-- removed,getoutput
,getstatusoutput
moved tosubprocess
urlparse
-- removed,urlparse
moved tourllib.parse
cStringIO
-- removed, useStringIO
orio.StringIO
copy_reg
-- renamedcopyreg
_winreg
-- renamedwinreg
ConfigParser
-- renamedconfigparser
__builtin__
-- renamedbuiltins
In the case of
cPickle
, it is imported aspickle
when python < 3 andperformance may be a consideration, but otherwise plain old
pickle
isused.
Dealing with
StringIO
is a bit tricky. There is anio.StringIO
function in the
io
module, available since Python 2.6, but it expectsunicode whereas
StringIO.StringIO
expects ascii. The Python 3equivalent is then
io.BytesIO
. What I have done here is used BytesIOfor anything that is emulating a file for testing purposes. That is more
explicit than using a redefined StringIO as was done before we dropped
support for Python 2.4 and 2.5.
Closes #3180.