Remove usage of 'long' data type

Data type 'long' is gone in python3, we'd better avoid using it by
taking advantage of 'six'.

Change-Id: I9e556d412180c4ff84837df914eb8c17465921df
This commit is contained in:
tengqm 2015-03-18 10:43:43 +08:00
parent 831f4beaf4
commit b40089c623
3 changed files with 8 additions and 11 deletions

View File

@ -252,7 +252,7 @@ class Select(function.Function):
if (isinstance(strings, collections.Sequence) and
not isinstance(strings, six.string_types)):
if not isinstance(index, (int, long)):
if not isinstance(index, six.integer_types):
raise TypeError(_('Index to "%s" must be an integer') %
self.fn_name)
@ -434,7 +434,8 @@ class Replace(function.Function):
value = ''
if not isinstance(value,
(six.string_types, int, long, float, bool)):
(six.string_types, six.integer_types,
float, bool)):
raise TypeError(_('"%s" params must be strings or numbers') %
self.fn_name)

View File

@ -244,7 +244,7 @@ class AnyIndexDict(collections.Mapping):
self.value = value
def __getitem__(self, key):
if key != self.ANYTHING and not isinstance(key, (int, long)):
if key != self.ANYTHING and not isinstance(key, six.integer_types):
raise KeyError(_('Invalid key %s') % str(key))
return self.value
@ -333,7 +333,7 @@ class Range(Constraint):
self.max = max
for param in (min, max):
if not isinstance(param, (float, int, long, type(None))):
if not isinstance(param, (float, six.integer_types, type(None))):
raise exception.InvalidSchemaError(
message=_('min/max must be numeric'))
@ -402,7 +402,7 @@ class Length(Range):
super(Length, self).__init__(min, max, description)
for param in (min, max):
if not isinstance(param, (int, long, type(None))):
if not isinstance(param, (six.integer_types, type(None))):
msg = _('min/max length must be integral')
raise exception.InvalidSchemaError(message=msg)

View File

@ -29,6 +29,7 @@ from oslo_db.sqlalchemy import test_base
from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils
from oslo_serialization import jsonutils
import six
from heat.db.sqlalchemy import migrate_repo
from heat.db.sqlalchemy import migration
@ -546,12 +547,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
# confirm the resource.id is an int and the uuid field has been
# copied from the old id.
for r in res_in_db:
# now sqlalchemy returns `long` for mysql
# need more convenient way for type check
if engine.name == 'mysql':
self.assertEqual(long, type(r.id))
else:
self.assertEqual(int, type(r.id))
self.assertIsInstance(r.id, six.integer_types)
self.assertTrue(uuid_in_res_data(r.uuid))
# confirm that the new resource_id points to the correct resource.