Merge lp:~cjwatson/storm/py3-integer-types into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 498
Proposed branch: lp:~cjwatson/storm/py3-integer-types
Merge into: lp:storm
Diff against target: 248 lines (+40/-18)
8 files modified
dev/ubuntu-deps (+5/-4)
setup.py (+1/-0)
storm/expr.py (+4/-2)
storm/store.py (+3/-1)
storm/variables.py (+7/-5)
tests/expr.py (+9/-2)
tests/store/base.py (+4/-2)
tests/variables.py (+7/-2)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-integer-types
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
Review via email: mp+368381@code.launchpad.net

Commit message

Handle Python 3's int/long changes (PEP 237).

Description of the change

This introduces a run-time dependency on six. At the moment this is used quite lightly, but we'll need more from it as the Python 3 port progresses, so I think it makes more sense to use it than to reinvent it, especially as it's already a very popular package.

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

Looks good - can I ask that the ubuntu-deps change be sorted though, (i.e. insert after psycopg2)

review: Approve
lp:~cjwatson/storm/py3-integer-types updated
499. By Colin Watson

Sort dev/ubuntu-deps.

Revision history for this message
Colin Watson (cjwatson) wrote :

Mm, that list was somewhat unsorted. I've sorted the whole thing now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dev/ubuntu-deps'
2--- dev/ubuntu-deps 2019-05-30 13:21:20 +0000
3+++ dev/ubuntu-deps 2019-06-05 10:53:51 +0000
4@@ -6,19 +6,20 @@
5 }
6
7 apt_get install --no-install-recommends \
8+ build-essential \
9+ libpq-dev \
10+ pgbouncer \
11 postgresql \
12- pgbouncer \
13- libpq-dev \
14- build-essential \
15 python-dev \
16 python-fixtures \
17 python-psycopg2 \
18+ python-setuptools \
19+ python-six \
20 python-testresources \
21 python-transaction \
22 python-twisted \
23 python-zope.component \
24 python-zope.security \
25- python-setuptools \
26 tox
27
28
29
30=== modified file 'setup.py'
31--- setup.py 2019-06-05 09:56:39 +0000
32+++ setup.py 2019-06-05 10:53:51 +0000
33@@ -64,6 +64,7 @@
34 # warning) by distutils.
35 include_package_data=True,
36 zip_safe=False,
37+ install_requires=["six"],
38 test_suite="tests.find_tests",
39 tests_require=tests_require,
40 extras_require={"test": tests_require},
41
42=== modified file 'storm/expr.py'
43--- storm/expr.py 2016-05-13 18:55:24 +0000
44+++ storm/expr.py 2019-06-05 10:53:51 +0000
45@@ -24,6 +24,8 @@
46 from copy import copy
47 import re
48
49+import six
50+
51 from storm.exceptions import CompileError, NoTableError, ExprError
52 from storm.variables import (
53 Variable, RawStrVariable, UnicodeVariable, LazyValue,
54@@ -313,7 +315,7 @@
55 state.parameters.append(UnicodeVariable(expr))
56 return "?"
57
58-@compile.when(int, long)
59+@compile.when(*six.integer_types)
60 def compile_int(compile, expr, state):
61 state.parameters.append(IntVariable(expr))
62 return "?"
63@@ -358,7 +360,7 @@
64 return "NULL"
65
66
67-@compile_python.when(str, unicode, int, long, float, type(None))
68+@compile_python.when(str, unicode, float, type(None), *six.integer_types)
69 def compile_python_builtin(compile, expr, state):
70 return repr(expr)
71
72
73=== modified file 'storm/store.py'
74--- storm/store.py 2015-04-20 08:46:56 +0000
75+++ storm/store.py 2019-06-05 10:53:51 +0000
76@@ -28,6 +28,8 @@
77 from weakref import WeakValueDictionary
78 from operator import itemgetter
79
80+import six
81+
82 from storm.info import get_cls_info, get_obj_info, set_obj_info
83 from storm.variables import Variable, LazyValue
84 from storm.expr import (
85@@ -1003,7 +1005,7 @@
86 L{ResultSet} will be returned appropriately modified with
87 C{OFFSET} and C{LIMIT} clauses.
88 """
89- if isinstance(index, (int, long)):
90+ if isinstance(index, six.integer_types):
91 if index == 0:
92 result_set = self
93 else:
94
95=== modified file 'storm/variables.py'
96--- storm/variables.py 2019-06-05 09:49:47 +0000
97+++ storm/variables.py 2019-06-05 10:53:51 +0000
98@@ -26,6 +26,8 @@
99 import uuid
100 import weakref
101
102+import six
103+
104 from storm.compat import json
105 from storm.exceptions import NoneError
106 from storm import Undef, has_cextensions
107@@ -313,7 +315,7 @@
108 __slots__ = ()
109
110 def parse_set(self, value, from_db):
111- if not isinstance(value, (int, long, float, Decimal)):
112+ if not isinstance(value, (six.integer_types, float, Decimal)):
113 raise TypeError("Expected bool, found %r: %r"
114 % (type(value), value))
115 return bool(value)
116@@ -323,7 +325,7 @@
117 __slots__ = ()
118
119 def parse_set(self, value, from_db):
120- if not isinstance(value, (int, long, float, Decimal)):
121+ if not isinstance(value, (six.integer_types, float, Decimal)):
122 raise TypeError("Expected int, found %r: %r"
123 % (type(value), value))
124 return int(value)
125@@ -333,7 +335,7 @@
126 __slots__ = ()
127
128 def parse_set(self, value, from_db):
129- if not isinstance(value, (int, long, float, Decimal)):
130+ if not isinstance(value, (six.integer_types, float, Decimal)):
131 raise TypeError("Expected float, found %r: %r"
132 % (type(value), value))
133 return float(value)
134@@ -345,7 +347,7 @@
135 @staticmethod
136 def parse_set(value, from_db):
137 if (from_db and isinstance(value, basestring) or
138- isinstance(value, (int, long))):
139+ isinstance(value, six.integer_types)):
140 value = Decimal(value)
141 elif not isinstance(value, Decimal):
142 raise TypeError("Expected Decimal, found %r: %r"
143@@ -406,7 +408,7 @@
144 else:
145 value = value.astimezone(self._tzinfo)
146 else:
147- if type(value) in (int, long, float):
148+ if type(value) in six.integer_types + (float, ):
149 value = datetime.utcfromtimestamp(value)
150 elif not isinstance(value, datetime):
151 raise TypeError("Expected datetime, found %s" % repr(value))
152
153=== modified file 'tests/expr.py'
154--- tests/expr.py 2012-03-26 14:27:29 +0000
155+++ tests/expr.py 2019-06-05 10:53:51 +0000
156@@ -19,6 +19,9 @@
157 # along with this program. If not, see <http://www.gnu.org/licenses/>.
158 #
159 from decimal import Decimal
160+import unittest
161+
162+import six
163
164 from tests.helper import TestHelper
165
166@@ -584,9 +587,11 @@
167 self.assertEquals(statement, "?")
168 self.assertVariablesEqual(state.parameters, [IntVariable(1)])
169
170+ @unittest.skipUnless(six.PY2, "Python 3 has no separate long type")
171 def test_long(self):
172 state = State()
173- statement = compile(1L, state)
174+ # 1L was more idiomatic in Python 2, but is a syntax error in Python 3.
175+ statement = compile(long(1), state)
176 self.assertEquals(statement, "?")
177 self.assertVariablesEqual(state.parameters, [IntVariable(1)])
178
179@@ -2171,8 +2176,10 @@
180 py_expr = compile_python(1)
181 self.assertEquals(py_expr, "1")
182
183+ @unittest.skipUnless(six.PY2, "Python 3 has no separate long type")
184 def test_long(self):
185- py_expr = compile_python(1L)
186+ # 1L was more idiomatic in Python 2, but is a syntax error in Python 3.
187+ py_expr = compile_python(long(1))
188 self.assertEquals(py_expr, "1L")
189
190 def test_bool(self):
191
192=== modified file 'tests/store/base.py'
193--- tests/store/base.py 2019-05-31 15:56:35 +0000
194+++ tests/store/base.py 2019-06-05 10:53:51 +0000
195@@ -28,6 +28,8 @@
196 from uuid import uuid4
197 import weakref
198
199+import six
200+
201 from storm.references import Reference, ReferenceSet, Proxy
202 from storm.database import Result, STATE_DISCONNECTED
203 from storm.properties import (
204@@ -1576,7 +1578,7 @@
205 result.group_by(FooValue.value2)
206 result.order_by(Count(FooValue.id), Sum(FooValue.value1))
207 result = list(result)
208- self.assertEquals(result, [(2L, 2L), (2L, 2L), (2L, 3L), (3L, 6L)])
209+ self.assertEquals(result, [(2, 2), (2, 2), (2, 3), (3, 6)])
210
211 def test_find_group_by_table(self):
212 result = self.store.find(
213@@ -5276,7 +5278,7 @@
214 self.store.add(foo)
215 foo.id = AutoReload
216 foo.title = u"New Title"
217- self.assertTrue(isinstance(foo.id, (int, long)))
218+ self.assertTrue(isinstance(foo.id, six.integer_types))
219 self.assertEquals(foo.title, "New Title")
220
221 def test_autoreload_primary_key_doesnt_reload_everything_else(self):
222
223=== modified file 'tests/variables.py'
224--- tests/variables.py 2019-06-03 08:45:24 +0000
225+++ tests/variables.py 2019-06-05 10:53:51 +0000
226@@ -25,6 +25,8 @@
227 import weakref
228 import uuid
229
230+import six
231+
232 from storm.compat import json
233 from storm.exceptions import NoneError
234 from storm.variables import *
235@@ -464,8 +466,11 @@
236 self.assertEquals(variable.get(), epoch)
237 variable.set(0.0)
238 self.assertEquals(variable.get(), epoch)
239- variable.set(0L)
240- self.assertEquals(variable.get(), epoch)
241+ if six.PY2:
242+ # 1L was more idiomatic in Python 2, but is a syntax error in
243+ # Python 3.
244+ variable.set(long(0))
245+ self.assertEquals(variable.get(), epoch)
246 variable.set(epoch)
247 self.assertEquals(variable.get(), epoch)
248 self.assertRaises(TypeError, variable.set, marker)

Subscribers

People subscribed via source and target branches

to status/vote changes: