[py3k] 'long' and 'unicode' are no longer available
authorRémi Cardona <remi.cardona@free.fr>
Fri, 25 Jul 2014 00:28:03 +0200
changeset 750 e554893cccb6
parent 749 c6aa72c82081
child 751 1e454af7ac93
[py3k] 'long' and 'unicode' are no longer available Use six-provided "types" whenever possible.
nodes.py
stmts.py
test/unittest_nodes.py
test/unittest_parser.py
--- a/nodes.py	Thu Jul 24 02:26:50 2014 +0200
+++ b/nodes.py	Fri Jul 25 00:28:03 2014 +0200
@@ -23,6 +23,7 @@
 
 __docformat__ = "restructuredtext en"
 
+import sys
 from itertools import chain
 from decimal import Decimal
 from datetime import datetime, date, time, timedelta
@@ -41,16 +42,17 @@
 
 ETYPE_PYOBJ_MAP = { bool: 'Boolean',
                     int: 'Int',
-                    long: 'Int',
                     float: 'Float',
                     Decimal: 'Decimal',
-                    unicode: 'String',
                     str: 'String',
                     datetime: 'Datetime',
                     date: 'Date',
                     time: 'Time',
                     timedelta: 'Interval',
                     }
+if sys.version_info < (3,):
+    ETYPE_PYOBJ_MAP[long] = 'Int'
+    ETYPE_PYOBJ_MAP[unicode] = 'String'
 
 KEYWORD_MAP = {'NOW' : datetime.now,
                'TODAY': date.today}
--- a/stmts.py	Thu Jul 24 02:26:50 2014 +0200
+++ b/stmts.py	Fri Jul 25 00:28:03 2014 +0200
@@ -28,6 +28,7 @@
 from copy import deepcopy
 from warnings import warn
 
+from six import integer_types
 from six.moves import range
 
 from logilab.common.decorators import cached
@@ -561,7 +562,7 @@
         self.distinct = value
 
     def set_limit(self, limit):
-        if limit is not None and (not isinstance(limit, (int, long)) or limit <= 0):
+        if limit is not None and (not isinstance(limit, integer_types) or limit <= 0):
             raise BadRQLQuery('bad limit %s' % limit)
         if self.should_register_op and limit != self.limit:
             from rql.undo import SetLimitOperation
@@ -569,7 +570,7 @@
         self.limit = limit
 
     def set_offset(self, offset):
-        if offset is not None and (not isinstance(offset, (int, long)) or offset < 0):
+        if offset is not None and (not isinstance(offset, integer_types) or offset < 0):
             raise BadRQLQuery('bad offset %s' % offset)
         if self.should_register_op and offset != self.offset:
             from rql.undo import SetOffsetOperation
--- a/test/unittest_nodes.py	Thu Jul 24 02:26:50 2014 +0200
+++ b/test/unittest_nodes.py	Fri Jul 25 00:28:03 2014 +0200
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with rql. If not, see <http://www.gnu.org/licenses/>.
 
+import sys
 from datetime import date, datetime
 
 from logilab.common.testlib import TestCase, unittest_main
@@ -41,7 +42,9 @@
 
     def test_int(self):
         self.assertEqual(nodes.etype_from_pyobj(0), 'Int')
-        self.assertEqual(nodes.etype_from_pyobj(1L), 'Int')
+        if sys.version_info < (3,):
+            l = long
+            self.assertEqual(nodes.etype_from_pyobj(l('1L')), 'Int')
 
     def test_float(self):
         self.assertEqual(nodes.etype_from_pyobj(0.), 'Float')
--- a/test/unittest_parser.py	Thu Jul 24 02:26:50 2014 +0200
+++ b/test/unittest_parser.py	Fri Jul 25 00:28:03 2014 +0200
@@ -18,6 +18,8 @@
 # with rql. If not, see <http://www.gnu.org/licenses/>.
 from __future__ import print_function
 
+from six import text_type
+
 from logilab.common.testlib import TestCase, unittest_main
 
 from yapps.runtime import print_error, SyntaxError
@@ -190,7 +192,7 @@
         comparison = base.children[1]
         self.assertIsInstance(comparison, nodes.Comparison)
         rhs = comparison.children[0]
-        self.assertEqual(type(rhs.value), unicode)
+        self.assertIsInstance(rhs.value, text_type)
 
     def test_precedence_1(self):
         tree = self.parse("Any X WHERE X firstname 'lulu' AND X name 'toto' OR X name 'tutu';")