Skip to content

Commit 49a8902

Browse files
committed
Merge pull request numpy#3191 from charris/2to3-apply-imports-fixer
2to3: Apply `imports` fixer.
2 parents 3c8fc14 + 4394515 commit 49a8902

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+514
-452
lines changed

doc/cdoc/numpyfilter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import os
1414
import textwrap
1515
import optparse
16-
import cPickle as pickle
16+
17+
if sys.version_info[0] >= 3:
18+
import pickle
19+
else:
20+
import cPickle as pickle
1721

1822
CACHE_FILE = 'build/rst-cache.pck'
1923

@@ -43,7 +47,7 @@ def filter_comment(text):
4347
if text.startswith('UFUNC_API'):
4448
text = text[9:].strip()
4549

46-
html = render_html(text)
50+
html = render_html(text)
4751
return html
4852

4953
def process_match(m, cache=None):

doc/numpybook/runcode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import sys
2020
import optparse
21-
import cStringIO
21+
import io
2222
import re
2323
import os
2424

@@ -27,7 +27,7 @@
2727
def getoutput(tstr, dic):
2828
print "\n\nRunning..."
2929
print tstr,
30-
tempstr = cStringIO.StringIO()
30+
tempstr = io.StringIO()
3131
sys.stdout = tempstr
3232
code = compile(tstr, '<input>', 'exec')
3333
try:
@@ -82,7 +82,7 @@ def getnewcodestr(substr, dic):
8282

8383
def runpycode(lyxstr, name='MyCode'):
8484
schobj = re.compile(r"\\layout %s\s+>>> " % name)
85-
outstr = cStringIO.StringIO()
85+
outstr = io.StringIO()
8686
num = 0
8787
indx = []
8888
for it in schobj.finditer(lyxstr):

doc/sphinxext/numpydoc/comment_eater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
if sys.version_info[0] >= 3:
55
from io import StringIO
66
else:
7-
from cStringIO import StringIO
7+
from io import StringIO
88

99
import compiler
1010
import inspect

doc/sphinxext/numpydoc/compiler_unparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
if sys.version_info[0] >= 3:
1919
from io import StringIO
2020
else:
21-
from cStringIO import StringIO
21+
from io import StringIO
2222

2323
def unparse(ast, single_line_functions=False):
2424
s = StringIO()

doc/sphinxext/numpydoc/docscrape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if sys.version_info[0] >= 3:
1515
from io import StringIO
1616
else:
17-
from cStringIO import StringIO
17+
from io import StringIO
1818

1919
class Reader(object):
2020
"""A line-based string reader.

doc/sphinxext/numpydoc/plot_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
if sys.version_info[0] >= 3:
8383
from io import StringIO
8484
else:
85-
from cStringIO import StringIO
85+
from io import StringIO
8686

8787
import warnings
8888
warnings.warn("A plot_directive module is also available under "

numpy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
"""
107107
from __future__ import division, absolute_import
108108

109+
import sys
110+
109111
# We first need to detect if we're being called as part of the numpy setup
110112
# procedure itself in a reliable manner.
111113
try:
@@ -160,8 +162,11 @@ def pkgload(*packages, **options):
160162

161163
# Make these accessible from numpy name-space
162164
# but not imported in from numpy import *
163-
from __builtin__ import bool, int, long, float, complex, \
164-
object, unicode, str
165+
if sys.version_info[0] >= 3:
166+
from builtins import bool, int, long, float, complex, object, unicode, str
167+
else:
168+
from __builtin__ import bool, int, long, float, complex, object, unicode, str
169+
165170
from .core import round, abs, max, min
166171

167172
__all__.extend(['__version__', 'pkgload', 'PackageLoader',

numpy/core/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def _ufunc_reduce(func):
6262

6363

6464
import sys
65-
if sys.version_info[0] < 3:
66-
import copy_reg as copyreg
67-
else:
65+
if sys.version_info[0] >= 3:
6866
import copyreg
67+
else:
68+
import copy_reg as copyreg
6969

7070
copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct)
7171
# Unclutter namespace (must keep _ufunc_reconstruct for unpickling)

numpy/core/numeric.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
from __future__ import division, absolute_import
22

3+
import sys
4+
import warnings
5+
from . import multiarray
6+
from . import umath
7+
from .umath import *
8+
from . import numerictypes
9+
from .numerictypes import *
10+
import collections
11+
12+
if sys.version_info[0] >= 3:
13+
import pickle
14+
else:
15+
import cPickle as pickle
16+
17+
loads = pickle.loads
18+
19+
320
__all__ = ['newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc',
421
'arange', 'array', 'zeros', 'count_nonzero',
522
'empty', 'broadcast', 'dtype', 'fromstring', 'fromfile',
@@ -24,19 +41,10 @@
2441
'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS',
2542
'ComplexWarning']
2643

27-
import sys
28-
import warnings
29-
from . import multiarray
30-
from . import umath
31-
from .umath import *
32-
from . import numerictypes
33-
from .numerictypes import *
34-
import collections
35-
36-
3744
if sys.version_info[0] < 3:
3845
__all__.extend(['getbuffer', 'newbuffer'])
3946

47+
4048
class ComplexWarning(RuntimeWarning):
4149
"""
4250
The warning raised when casting a complex dtype to a real dtype.
@@ -1861,9 +1869,6 @@ def base_repr(number, base=2, padding=0):
18611869
res.append('-')
18621870
return ''.join(reversed(res or '0'))
18631871

1864-
from cPickle import load, loads
1865-
_cload = load
1866-
_file = open
18671872

18681873
def load(file):
18691874
"""
@@ -1880,8 +1885,8 @@ def load(file):
18801885
18811886
"""
18821887
if isinstance(file, type("")):
1883-
file = _file(file,"rb")
1884-
return _cload(file)
1888+
file = open(file, "rb")
1889+
return pickle.load(file)
18851890

18861891
# These are all essentially abbreviations
18871892
# These might wind up in a special abbreviations module

numpy/core/numerictypes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@
9898

9999
# we don't export these for import *, but we do want them accessible
100100
# as numerictypes.bool, etc.
101-
from __builtin__ import bool, int, long, float, complex, object, unicode, str
101+
if sys.version_info[0] >= 3:
102+
from builtins import bool, int, long, float, complex, object, unicode, str
103+
else:
104+
from __builtin__ import bool, int, long, float, complex, object, unicode, str
105+
102106
from numpy.compat import bytes
103107

104108
if sys.version_info[0] >= 3:

0 commit comments

Comments
 (0)