Merge lp:~cjwatson/storm/py3-exceptions into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 491
Proposed branch: lp:~cjwatson/storm/py3-exceptions
Merge into: lp:storm
Prerequisite: lp:~cjwatson/storm/tox
Diff against target: 391 lines (+37/-37)
15 files modified
storm/__init__.py (+1/-1)
storm/database.py (+5/-5)
storm/databases/sqlite.py (+1/-1)
storm/schema/schema.py (+1/-1)
storm/schema/sharding.py (+1/-1)
storm/twisted/transact.py (+1/-1)
tests/databases/base.py (+4/-4)
tests/databases/postgres.py (+2/-2)
tests/databases/sqlite.py (+2/-2)
tests/mocker.py (+7/-7)
tests/schema/patch.py (+4/-4)
tests/store/base.py (+1/-1)
tests/tracer.py (+2/-2)
tests/variables.py (+4/-4)
tests/zope/zstorm.py (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-exceptions
Reviewer Review Type Date Requested Status
Simon Poirier (community) Approve
Review via email: mp+368143@code.launchpad.net

Commit message

Use Python 3-friendly "except" syntax.

Description of the change

This is a tiny subset of Thiago Bellini's work in https://code.launchpad.net/~bellini666/storm/py3/+merge/325182, though I did this part of it independently. I'm trying to carve out some of the straightforward mechanical changes from that branch in order to make it reviewable in a reasonable amount of time.

To post a comment you must log in.
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 LGTM

<3 short mechanical reviews

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/__init__.py'
2--- storm/__init__.py 2013-06-28 09:56:58 +0000
3+++ storm/__init__.py 2019-05-30 13:43:46 +0000
4@@ -53,6 +53,6 @@
5 try:
6 from storm import cextensions
7 has_cextensions = True
8- except ImportError, e:
9+ except ImportError as e:
10 if "cextensions" not in str(e):
11 raise
12
13=== modified file 'storm/database.py'
14--- storm/database.py 2015-06-15 13:42:07 +0000
15+++ storm/database.py 2019-05-30 13:43:46 +0000
16@@ -318,7 +318,7 @@
17 self._raw_connection.tpc_rollback()
18 else:
19 self._raw_connection.rollback()
20- except Error, exc:
21+ except Error as exc:
22 if self.is_disconnection_error(exc):
23 self._raw_connection = None
24 self._state = STATE_RECONNECT
25@@ -386,7 +386,7 @@
26 """Complete the statement execution, along with result reports."""
27 try:
28 self._check_disconnect(raw_cursor.execute, *args)
29- except Exception, error:
30+ except Exception as error:
31 self._check_disconnect(
32 trace, "connection_raw_execute_error", self, raw_cursor,
33 statement, params or (), error)
34@@ -402,7 +402,7 @@
35 self._check_disconnect(
36 trace, "connection_raw_execute", self, raw_cursor,
37 statement, params or ())
38- except Exception, error:
39+ except Exception as error:
40 self._check_disconnect(
41 trace, "connection_raw_execute_error", self, raw_cursor,
42 statement, params or (), error)
43@@ -423,7 +423,7 @@
44 elif self._state == STATE_RECONNECT:
45 try:
46 self._raw_connection = self._database.raw_connect()
47- except DatabaseError, exc:
48+ except DatabaseError as exc:
49 self._state = STATE_DISCONNECTED
50 self._raw_connection = None
51 raise DisconnectionError(str(exc))
52@@ -452,7 +452,7 @@
53 'extra_disconnection_errors', ())
54 try:
55 return function(*args, **kwargs)
56- except Exception, exc:
57+ except Exception as exc:
58 if self.is_disconnection_error(exc, extra_disconnection_errors):
59 self._state = STATE_DISCONNECTED
60 self._raw_connection = None
61
62=== modified file 'storm/databases/sqlite.py'
63--- storm/databases/sqlite.py 2015-06-15 12:02:12 +0000
64+++ storm/databases/sqlite.py 2019-05-30 13:43:46 +0000
65@@ -157,7 +157,7 @@
66 while True:
67 try:
68 return Connection.raw_execute(self, statement, params)
69- except sqlite.OperationalError, e:
70+ except sqlite.OperationalError as e:
71 if str(e) != "database is locked":
72 raise
73 elif now() - started < self._database._timeout:
74
75=== modified file 'storm/schema/schema.py'
76--- storm/schema/schema.py 2015-01-26 09:57:25 +0000
77+++ storm/schema/schema.py 2019-05-30 13:43:46 +0000
78@@ -172,7 +172,7 @@
79 except SchemaMissingError:
80 # No schema at all. Create it from the ground.
81 self.create(store)
82- except UnappliedPatchesError, error:
83+ except UnappliedPatchesError as error:
84 patch_applier.check_unknown()
85 for version in error.unapplied_versions:
86 self.advance(store, version)
87
88=== modified file 'storm/schema/sharding.py'
89--- storm/schema/sharding.py 2014-12-28 11:51:53 +0000
90+++ storm/schema/sharding.py 2019-05-30 13:43:46 +0000
91@@ -101,7 +101,7 @@
92 schema.check(store)
93 except SchemaMissingError:
94 schema.create(store)
95- except UnappliedPatchesError, error:
96+ except UnappliedPatchesError as error:
97 if not unapplied_versions:
98 unapplied_versions = error.unapplied_versions
99 elif unapplied_versions != error.unapplied_versions:
100
101=== modified file 'storm/twisted/transact.py'
102--- storm/twisted/transact.py 2011-12-07 10:39:57 +0000
103+++ storm/twisted/transact.py 2019-05-30 13:43:46 +0000
104@@ -75,7 +75,7 @@
105 try:
106 result = function(*args, **kwargs)
107 self._transaction.commit()
108- except RETRIABLE_ERRORS, error:
109+ except RETRIABLE_ERRORS as error:
110 if isinstance(error, DisconnectionError):
111 # If we got a disconnection, calling rollback may not be
112 # enough because psycopg2 doesn't necessarily use the
113
114=== modified file 'tests/databases/base.py'
115--- tests/databases/base.py 2016-03-10 12:04:01 +0000
116+++ tests/databases/base.py 2019-05-30 13:43:46 +0000
117@@ -344,7 +344,7 @@
118 connection2.execute("UPDATE test SET title='Title 100' "
119 "WHERE id=10")
120 connection2.commit()
121- except OperationalError, e:
122+ except OperationalError as e:
123 self.assertEquals(str(e), "database is locked") # SQLite blocks
124 result = connection1.execute("SELECT title FROM test WHERE id=10")
125 self.assertEquals(result.get_one(), ("Title 10",))
126@@ -770,7 +770,7 @@
127 cursor = self.connection._raw_connection.cursor()
128 cursor.execute("SELECT 1")
129 cursor.fetchone()
130- except Error, exc:
131+ except Error as exc:
132 self.assertTrue(self.connection.is_disconnection_error(exc))
133 else:
134 self.fail("Disconnection was not caught.")
135@@ -779,7 +779,7 @@
136 # error when called.
137 try:
138 self.connection._raw_connection.rollback()
139- except Error, exc:
140+ except Error as exc:
141 self.assertTrue(self.connection.is_disconnection_error(exc))
142 else:
143 self.fail("Disconnection was not raised.")
144@@ -803,7 +803,7 @@
145 cursor = self.connection._raw_connection.cursor()
146 cursor.execute("SELECT 1")
147 cursor.fetchone()
148- except DatabaseError, exc:
149+ except DatabaseError as exc:
150 self.assertTrue(self.connection.is_disconnection_error(exc))
151 else:
152 self.fail("Disconnection was not caught.")
153
154=== modified file 'tests/databases/postgres.py'
155--- tests/databases/postgres.py 2016-04-29 08:38:51 +0000
156+++ tests/databases/postgres.py 2019-05-30 13:43:46 +0000
157@@ -741,7 +741,7 @@
158 self.connection._raw_connection = FakeConnection()
159 try:
160 self.connection.rollback()
161- except Exception, exc:
162+ except Exception as exc:
163 self.fail('Exception should have been swallowed: %s' % repr(exc))
164
165
166@@ -875,7 +875,7 @@
167 self.remaining_time = 0.001
168 try:
169 self.connection.execute(statement)
170- except TimeoutError, e:
171+ except TimeoutError as e:
172 self.assertEqual("SQL server cancelled statement", e.message)
173 self.assertEqual(statement, e.statement)
174 self.assertEqual((), e.params)
175
176=== modified file 'tests/databases/sqlite.py'
177--- tests/databases/sqlite.py 2013-05-05 10:36:13 +0000
178+++ tests/databases/sqlite.py 2019-05-30 13:43:46 +0000
179@@ -114,7 +114,7 @@
180 started = time.time()
181 try:
182 connection2.execute("INSERT INTO test VALUES (2)")
183- except OperationalError, exception:
184+ except OperationalError as exception:
185 self.assertEquals(str(exception), "database is locked")
186 self.assertTrue(time.time()-started >= 0.3)
187 else:
188@@ -141,7 +141,7 @@
189 started = time.time()
190 try:
191 connection1.commit()
192- except OperationalError, exception:
193+ except OperationalError as exception:
194 self.assertEquals(str(exception), "database is locked")
195 # In 0.10, the next assertion failed because the timeout wasn't
196 # enforced for the "COMMIT" statement.
197
198=== modified file 'tests/mocker.py'
199--- tests/mocker.py 2008-05-18 10:22:29 +0000
200+++ tests/mocker.py 2019-05-30 13:43:46 +0000
201@@ -487,7 +487,7 @@
202 for event in self._events:
203 try:
204 event.verify()
205- except AssertionError, e:
206+ except AssertionError as e:
207 error = str(e)
208 if not error:
209 raise RuntimeError("Empty error message from %r"
210@@ -1029,7 +1029,7 @@
211 path.root_object = object
212 try:
213 return self.__mocker__.act(path)
214- except MatchError, exception:
215+ except MatchError as exception:
216 root_mock = path.root_mock
217 if (path.root_object is not None and
218 root_mock.__mocker_passthrough__):
219@@ -1037,7 +1037,7 @@
220 # Reinstantiate to show raise statement on traceback, and
221 # also to make the traceback shown shorter.
222 raise MatchError(str(exception))
223- except AssertionError, e:
224+ except AssertionError as e:
225 lines = str(e).splitlines()
226 message = [ERROR_PREFIX + "Unmet expectation:", ""]
227 message.append("=> " + lines.pop(0))
228@@ -1083,7 +1083,7 @@
229 # something that doesn't offer them.
230 try:
231 result = self.__mocker_act__("len")
232- except MatchError, e:
233+ except MatchError as e:
234 raise AttributeError(str(e))
235 if type(result) is Mock:
236 return 0
237@@ -1092,7 +1092,7 @@
238 def __nonzero__(self):
239 try:
240 return self.__mocker_act__("nonzero")
241- except MatchError, e:
242+ except MatchError as e:
243 return True
244
245 def __iter__(self):
246@@ -1519,7 +1519,7 @@
247 for task in self._tasks:
248 try:
249 task_result = task.run(path)
250- except AssertionError, e:
251+ except AssertionError as e:
252 error = str(e)
253 if not error:
254 raise RuntimeError("Empty error message from %r" % task)
255@@ -1562,7 +1562,7 @@
256 for task in self._tasks:
257 try:
258 task.verify()
259- except AssertionError, e:
260+ except AssertionError as e:
261 error = str(e)
262 if not error:
263 raise RuntimeError("Empty error message from %r" % task)
264
265=== modified file 'tests/schema/patch.py'
266--- tests/schema/patch.py 2014-12-18 10:57:52 +0000
267+++ tests/schema/patch.py 2019-05-30 13:43:46 +0000
268@@ -345,7 +345,7 @@
269 self.add_module("patch_999.py", patch_no_args_apply)
270 try:
271 self.patch_applier.apply_all()
272- except BadPatchError, e:
273+ except BadPatchError as e:
274 self.assertTrue("mypackage/patch_999.py" in str(e))
275 self.assertTrue("takes no arguments" in str(e))
276 self.assertTrue("TypeError" in str(e))
277@@ -360,7 +360,7 @@
278 self.add_module("patch_999.py", patch_missing_apply)
279 try:
280 self.patch_applier.apply_all()
281- except BadPatchError, e:
282+ except BadPatchError as e:
283 self.assertTrue("mypackage/patch_999.py" in str(e))
284 self.assertTrue("no attribute" in str(e))
285 self.assertTrue("AttributeError" in str(e))
286@@ -375,7 +375,7 @@
287 self.add_module("patch_999.py", "that's not python")
288 try:
289 self.patch_applier.apply_all()
290- except BadPatchError, e:
291+ except BadPatchError as e:
292 self.assertTrue(" 999 " in str(e))
293 self.assertTrue("SyntaxError" in str(e))
294 else:
295@@ -389,7 +389,7 @@
296 self.add_module("patch_999.py", patch_name_error)
297 try:
298 self.patch_applier.apply_all()
299- except BadPatchError, e:
300+ except BadPatchError as e:
301 self.assertTrue("mypackage/patch_999.py" in str(e))
302 self.assertTrue("NameError" in str(e))
303 self.assertTrue("blah" in str(e))
304
305=== modified file 'tests/store/base.py'
306--- tests/store/base.py 2019-05-29 15:35:00 +0000
307+++ tests/store/base.py 2019-05-30 13:43:46 +0000
308@@ -5929,7 +5929,7 @@
309 self.store.commit()
310 try:
311 self.assertEquals(myfoo.title, title)
312- except AssertionError, e:
313+ except AssertionError as e:
314 raise AssertionError(unicode(e, 'replace') +
315 " (ensure your database was created with CREATE DATABASE"
316 " ... CHARACTER SET utf8)")
317
318=== modified file 'tests/tracer.py'
319--- tests/tracer.py 2012-06-28 14:21:49 +0000
320+++ tests/tracer.py 2019-05-30 13:43:46 +0000
321@@ -290,7 +290,7 @@
322
323 try:
324 self.execute()
325- except TimeoutError, e:
326+ except TimeoutError as e:
327 self.assertEqual("0 seconds remaining in time budget", e.message)
328 self.assertEqual(self.statement, e.statement)
329 self.assertEqual(self.params, e.params)
330@@ -662,7 +662,7 @@
331 try:
332 with CaptureTracer():
333 raise RuntimeError("boom")
334- except RuntimeError, error:
335+ except RuntimeError as error:
336 errors.append(error)
337 [error] = errors
338 self.assertEqual("boom", str(error))
339
340=== modified file 'tests/variables.py'
341--- tests/variables.py 2019-04-07 16:20:40 +0000
342+++ tests/variables.py 2019-05-30 13:43:46 +0000
343@@ -143,7 +143,7 @@
344 variable = CustomVariable(allow_none=False, column=column)
345 try:
346 variable.set(None)
347- except NoneError, e:
348+ except NoneError as e:
349 pass
350 self.assertTrue("column_name" in str(e))
351
352@@ -152,7 +152,7 @@
353 variable = CustomVariable(allow_none=False, column=column)
354 try:
355 variable.set(None)
356- except NoneError, e:
357+ except NoneError as e:
358 pass
359 self.assertTrue("table_name.column_name" in str(e))
360
361@@ -769,7 +769,7 @@
362 def test_unsupported_unit(self):
363 try:
364 self.check("1 month", None)
365- except ValueError, e:
366+ except ValueError as e:
367 self.assertEquals(str(e), "Unsupported interval unit 'month' "
368 "in interval '1 month'")
369 else:
370@@ -778,7 +778,7 @@
371 def test_missing_value(self):
372 try:
373 self.check("day", None)
374- except ValueError, e:
375+ except ValueError as e:
376 self.assertEquals(str(e), "Expected an interval value rather than "
377 "'day' in interval 'day'")
378 else:
379
380=== modified file 'tests/zope/zstorm.py'
381--- tests/zope/zstorm.py 2012-03-06 10:28:06 +0000
382+++ tests/zope/zstorm.py 2019-05-30 13:43:46 +0000
383@@ -355,7 +355,7 @@
384 store.execute("SELECT 1")
385 except ZStormError:
386 failures.append("ZStormError raised")
387- except Exception, exc:
388+ except Exception as exc:
389 failures.append("Expected ZStormError, got %r" % exc)
390 else:
391 failures.append("Expected ZStormError, nothing raised")

Subscribers

People subscribed via source and target branches

to status/vote changes: