Skip to content
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

2to3: Apply the numliterals fixer and skip the long fixer. #3232

Merged
merged 1 commit into from Apr 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions numpy/__init__.py
Expand Up @@ -159,13 +159,14 @@ def pkgload(*packages, **options):
from . import ma
from . import matrixlib as _mat
from .matrixlib import *
from .compat import long

# Make these accessible from numpy name-space
# but not imported in from numpy import *
if sys.version_info[0] >= 3:
from builtins import bool, int, long, float, complex, object, unicode, str
from builtins import bool, int, float, complex, object, unicode, str
else:
from __builtin__ import bool, int, long, float, complex, object, unicode, str
from __builtin__ import bool, int, float, complex, object, unicode, str

from .core import round, abs, max, min

Expand Down
9 changes: 8 additions & 1 deletion numpy/compat/py3k.py
Expand Up @@ -6,12 +6,14 @@

__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar',
'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested',
'asstr', 'open_latin1']
'asstr', 'open_latin1', 'long']

import sys

if sys.version_info[0] >= 3:
import io
long = int
integer_types = (int,)
bytes = bytes
unicode = str

Expand All @@ -38,13 +40,17 @@ def open_latin1(filename, mode='r'):

strchar = 'U'


else:
bytes = str
unicode = unicode
long = long
integer_types = (int, long)
asbytes = str
asstr = str
strchar = 'S'


def isfileobj(f):
return isinstance(f, file)

Expand All @@ -56,6 +62,7 @@ def asunicode(s):
def open_latin1(filename, mode='r'):
return open(filename, mode=mode)


def getexception():
return sys.exc_info()[1]

Expand Down
2 changes: 1 addition & 1 deletion numpy/core/defchararray.py
Expand Up @@ -22,7 +22,7 @@
from .numeric import ndarray, compare_chararrays
from .numeric import array as narray
from numpy.core.multiarray import _vec_string
from numpy.compat import asbytes
from numpy.compat import asbytes, long
import numpy

__all__ = ['chararray',
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/getlimits.py
Expand Up @@ -260,7 +260,7 @@ def min(self):
try:
val = iinfo._min_vals[self.key]
except KeyError:
val = int(-(1L << (self.bits-1)))
val = int(-(1 << (self.bits-1)))
iinfo._min_vals[self.key] = val
return val

Expand All @@ -272,9 +272,9 @@ def max(self):
val = iinfo._max_vals[self.key]
except KeyError:
if self.kind == 'u':
val = int((1L << self.bits) - 1)
val = int((1 << self.bits) - 1)
else:
val = int((1L << (self.bits-1)) - 1)
val = int((1 << (self.bits-1)) - 1)
iinfo._max_vals[self.key] = val
return val

Expand Down
3 changes: 2 additions & 1 deletion numpy/core/memmap.py
Expand Up @@ -3,10 +3,11 @@
__all__ = ['memmap']

import warnings
from .numeric import uint8, ndarray, dtype
import sys

import numpy as np
from .numeric import uint8, ndarray, dtype
from numpy.compat import long

dtypedescr = dtype
valid_filemodes = ["r", "c", "r+", "w+"]
Expand Down
22 changes: 9 additions & 13 deletions numpy/core/numerictypes.py
Expand Up @@ -90,26 +90,22 @@
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
]

from numpy.core.multiarray import typeinfo, ndarray, array, \
empty, dtype, datetime_data, datetime_as_string, \
busday_offset, busday_count, is_busday, busdaycalendar
from numpy.core.multiarray import (
typeinfo, ndarray, array, empty, dtype, datetime_data,
datetime_as_string, busday_offset, busday_count, is_busday,
busdaycalendar
)
import types as _types
import sys
from numpy.compat import bytes, long

# we don't export these for import *, but we do want them accessible
# as numerictypes.bool, etc.
if sys.version_info[0] >= 3:
from builtins import bool, int, long, float, complex, object, unicode, str
from builtins import bool, int, float, complex, object, unicode, str
else:
from __builtin__ import bool, int, long, float, complex, object, unicode, str
from __builtin__ import bool, int, float, complex, object, unicode, str

from numpy.compat import bytes

if sys.version_info[0] >= 3:
# Py3K
class long(int):
# Placeholder class -- this will not escape outside numerictypes.py
pass

# String-handling utilities to avoid locale-dependence.

Expand Down Expand Up @@ -861,7 +857,7 @@ def sctype2char(sctype):
_types.StringType, _types.UnicodeType, _types.BufferType]
except AttributeError:
# Py3K
ScalarType = [int, float, complex, long, bool, bytes, str, memoryview]
ScalarType = [int, float, complex, int, bool, bytes, str, memoryview]

ScalarType.extend(_sctype2char_dict.keys())
ScalarType = tuple(ScalarType)
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/records.py
Expand Up @@ -46,7 +46,7 @@
import os
import sys

from numpy.compat import isfileobj, bytes
from numpy.compat import isfileobj, bytes, long

ndarray = sb.ndarray

Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_regression.py
Expand Up @@ -17,7 +17,7 @@
assert_raises, assert_warns, dec
)
from numpy.testing.utils import _assert_valid_refcount, WarningManager
from numpy.compat import asbytes, asunicode, asbytes_nested
from numpy.compat import asbytes, asunicode, asbytes_nested, long

rlevel = 1

Expand Down
3 changes: 2 additions & 1 deletion numpy/core/tests/test_shape_base.py
Expand Up @@ -6,6 +6,7 @@
assert_equal, run_module_suite)
from numpy.core import (array, arange, atleast_1d, atleast_2d, atleast_3d,
vstack, hstack, newaxis, concatenate)
from numpy.compat import long

class TestAtleast1d(TestCase):
def test_0D_array(self):
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_r1array(self):
"""
assert_(atleast_1d(3).shape == (1,))
assert_(atleast_1d(3j).shape == (1,))
assert_(atleast_1d(3L).shape == (1,))
assert_(atleast_1d(long(3)).shape == (1,))
assert_(atleast_1d(3.0).shape == (1,))
assert_(atleast_1d([[2,3],[4,5]]).shape == (2,2))

Expand Down
5 changes: 3 additions & 2 deletions numpy/f2py/tests/test_return_complex.py
Expand Up @@ -2,6 +2,7 @@

from numpy.testing import *
from numpy import array
from numpy.compat import long
import util

class TestReturnComplex(util.F2PyTest):
Expand All @@ -13,7 +14,7 @@ def check_function(self, t):
err = 0.0
assert_( abs(t(234j)-234.0j)<=err)
assert_( abs(t(234.6)-234.6)<=err)
assert_( abs(t(234l)-234.0)<=err)
assert_( abs(t(long(234))-234.0)<=err)
assert_( abs(t(234.6+3j)-(234.6+3j))<=err)
#assert_( abs(t('234')-234.)<=err)
#assert_( abs(t('234.6')-234.6)<=err)
Expand Down Expand Up @@ -44,7 +45,7 @@ def check_function(self, t):
assert_raises(TypeError, t, {})

try:
r = t(10l**400)
r = t(10**400)
assert_( repr(r) in ['(inf+0j)','(Infinity+0j)'],repr(r))
except OverflowError:
pass
Expand Down
5 changes: 3 additions & 2 deletions numpy/f2py/tests/test_return_integer.py
Expand Up @@ -2,13 +2,14 @@

from numpy.testing import *
from numpy import array
from numpy.compat import long
import util

class TestReturnInteger(util.F2PyTest):
def check_function(self, t):
assert_( t(123)==123,repr(t(123)))
assert_( t(123.6)==123)
assert_( t(123l)==123)
assert_( t(long(123))==123)
assert_( t('123')==123)
assert_( t(-123)==-123)
assert_( t([123])==123)
Expand All @@ -34,7 +35,7 @@ def check_function(self, t):
assert_raises(Exception, t, {})

if t.__doc__.split()[0] in ['t8','s8']:
assert_raises(OverflowError, t, 100000000000000000000000l)
assert_raises(OverflowError, t, 100000000000000000000000)
assert_raises(OverflowError, t, 10000000011111111111111.23)

class TestF77ReturnInteger(TestReturnInteger):
Expand Down
5 changes: 3 additions & 2 deletions numpy/f2py/tests/test_return_logical.py
Expand Up @@ -2,6 +2,7 @@

from numpy.testing import *
from numpy import array
from numpy.compat import long
import util

class TestReturnLogical(util.F2PyTest):
Expand All @@ -15,7 +16,7 @@ def check_function(self, t):
assert_( t(1j)==1)
assert_( t(234)==1)
assert_( t(234.6)==1)
assert_( t(234l)==1)
assert_( t(long(234))==1)
assert_( t(234.6+3j)==1)
assert_( t('234')==1)
assert_( t('aaa')==1)
Expand All @@ -25,7 +26,7 @@ def check_function(self, t):
assert_( t({})==0)
assert_( t(t)==1)
assert_( t(-234)==1)
assert_( t(10l**100)==1)
assert_( t(10**100)==1)
assert_( t([234])==1)
assert_( t((234,))==1)
assert_( t(array(234))==1)
Expand Down
5 changes: 3 additions & 2 deletions numpy/f2py/tests/test_return_real.py
Expand Up @@ -2,6 +2,7 @@

from numpy.testing import *
from numpy import array
from numpy.compat import long
import math
import util

Expand All @@ -13,7 +14,7 @@ def check_function(self, t):
err = 0.0
assert_( abs(t(234)-234.0)<=err)
assert_( abs(t(234.6)-234.6)<=err)
assert_( abs(t(234l)-234.0)<=err)
assert_( abs(t(long(234))-234.0)<=err)
assert_( abs(t('234')-234)<=err)
assert_( abs(t('234.6')-234.6)<=err)
assert_( abs(t(-234)+234)<=err)
Expand Down Expand Up @@ -42,7 +43,7 @@ def check_function(self, t):
assert_raises(Exception, t, {})

try:
r = t(10l**400)
r = t(10**400)
assert_( repr(r) in ['inf','Infinity'],repr(r))
except OverflowError:
pass
Expand Down
6 changes: 3 additions & 3 deletions numpy/lib/_iotools.py
Expand Up @@ -10,11 +10,11 @@
import numpy.core.numeric as nx

if sys.version_info[0] >= 3:
from builtins import bool, int, long, float, complex, object, unicode, str
from builtins import bool, int, float, complex, object, unicode, str
else:
from __builtin__ import bool, int, long, float, complex, object, unicode, str
from __builtin__ import bool, int, float, complex, object, unicode, str

from numpy.compat import asbytes, bytes, asbytes_nested
from numpy.compat import asbytes, bytes, asbytes_nested, long

if sys.version_info[0] >= 3:
def _bytes_to_complex(s):
Expand Down
1 change: 1 addition & 0 deletions numpy/lib/arraypad.py
Expand Up @@ -6,6 +6,7 @@
from __future__ import division, absolute_import, print_function

import numpy as np
from numpy.compat import long

__all__ = ['pad']

Expand Down
6 changes: 4 additions & 2 deletions numpy/lib/arrayterator.py
Expand Up @@ -9,12 +9,14 @@
"""
from __future__ import division, absolute_import, print_function

import sys
from operator import mul
from functools import reduce

from numpy.compat import long

__all__ = ['Arrayterator']

import sys
from functools import reduce

class Arrayterator(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/format.py
Expand Up @@ -139,7 +139,7 @@
import numpy
import sys
from numpy.lib.utils import safe_eval
from numpy.compat import asbytes, isfileobj
from numpy.compat import asbytes, isfileobj, long

if sys.version_info[0] >= 3:
import pickle
Expand Down
1 change: 1 addition & 0 deletions numpy/lib/function_base.py
Expand Up @@ -32,6 +32,7 @@
from ._compiled_base import add_newdoc_ufunc
import numpy as np
import collections
from numpy.compat import long

# Force range to be a generator, for np.delete's usage.
if sys.version_info[0] < 3:
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/tests/test__datasource.py
Expand Up @@ -305,7 +305,7 @@ def test_CachedHTTPFile(self):
# would do.
scheme, netloc, upath, pms, qry, frg = urlparse(localfile)
local_path = os.path.join(self.repos._destpath, netloc)
os.mkdir(local_path, 0700)
os.mkdir(local_path, 0o0700)
tmpfile = valid_textfile(local_path)
assert_(self.repos.exists(tmpfile))

Expand Down
6 changes: 3 additions & 3 deletions numpy/lib/tests/test__iotools.py
Expand Up @@ -175,11 +175,11 @@ def test_upgrademapper(self):
StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
convert = StringConverter(dateparser, date(2000, 1, 1))
test = convert(asbytes('2001-01-01'))
assert_equal(test, date(2001, 01, 01))
assert_equal(test, date(2001, 1, 1))
test = convert(asbytes('2009-01-01'))
assert_equal(test, date(2009, 01, 01))
assert_equal(test, date(2009, 1, 1))
test = convert(asbytes(''))
assert_equal(test, date(2000, 01, 01))
assert_equal(test, date(2000, 1, 1))
#
def test_string_to_object(self):
"Make sure that string-to-object functions are properly recognized"
Expand Down
1 change: 1 addition & 0 deletions numpy/lib/tests/test_function_base.py
Expand Up @@ -9,6 +9,7 @@
)
from numpy.random import rand
from numpy.lib import *
from numpy.compat import long


class TestAny(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/tests/test_type_check.py
Expand Up @@ -3,7 +3,7 @@
from numpy.testing import *
from numpy.lib import *
from numpy.core import *
from numpy.compat import asbytes
from numpy.compat import asbytes, long

try:
import ctypes
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_basic(self):
assert_(not isscalar([3]))
assert_(not isscalar((3,)))
assert_(isscalar(3j))
assert_(isscalar(10L))
assert_(isscalar(long(10)))
assert_(isscalar(4.0))


Expand Down