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
=== modified file 'storm/__init__.py'
--- storm/__init__.py 2013-06-28 09:56:58 +0000
+++ storm/__init__.py 2019-05-30 13:43:46 +0000
@@ -53,6 +53,6 @@
53 try:53 try:
54 from storm import cextensions54 from storm import cextensions
55 has_cextensions = True55 has_cextensions = True
56 except ImportError, e:56 except ImportError as e:
57 if "cextensions" not in str(e):57 if "cextensions" not in str(e):
58 raise58 raise
5959
=== modified file 'storm/database.py'
--- storm/database.py 2015-06-15 13:42:07 +0000
+++ storm/database.py 2019-05-30 13:43:46 +0000
@@ -318,7 +318,7 @@
318 self._raw_connection.tpc_rollback()318 self._raw_connection.tpc_rollback()
319 else:319 else:
320 self._raw_connection.rollback()320 self._raw_connection.rollback()
321 except Error, exc:321 except Error as exc:
322 if self.is_disconnection_error(exc):322 if self.is_disconnection_error(exc):
323 self._raw_connection = None323 self._raw_connection = None
324 self._state = STATE_RECONNECT324 self._state = STATE_RECONNECT
@@ -386,7 +386,7 @@
386 """Complete the statement execution, along with result reports."""386 """Complete the statement execution, along with result reports."""
387 try:387 try:
388 self._check_disconnect(raw_cursor.execute, *args)388 self._check_disconnect(raw_cursor.execute, *args)
389 except Exception, error:389 except Exception as error:
390 self._check_disconnect(390 self._check_disconnect(
391 trace, "connection_raw_execute_error", self, raw_cursor,391 trace, "connection_raw_execute_error", self, raw_cursor,
392 statement, params or (), error)392 statement, params or (), error)
@@ -402,7 +402,7 @@
402 self._check_disconnect(402 self._check_disconnect(
403 trace, "connection_raw_execute", self, raw_cursor,403 trace, "connection_raw_execute", self, raw_cursor,
404 statement, params or ())404 statement, params or ())
405 except Exception, error:405 except Exception as error:
406 self._check_disconnect(406 self._check_disconnect(
407 trace, "connection_raw_execute_error", self, raw_cursor,407 trace, "connection_raw_execute_error", self, raw_cursor,
408 statement, params or (), error)408 statement, params or (), error)
@@ -423,7 +423,7 @@
423 elif self._state == STATE_RECONNECT:423 elif self._state == STATE_RECONNECT:
424 try:424 try:
425 self._raw_connection = self._database.raw_connect()425 self._raw_connection = self._database.raw_connect()
426 except DatabaseError, exc:426 except DatabaseError as exc:
427 self._state = STATE_DISCONNECTED427 self._state = STATE_DISCONNECTED
428 self._raw_connection = None428 self._raw_connection = None
429 raise DisconnectionError(str(exc))429 raise DisconnectionError(str(exc))
@@ -452,7 +452,7 @@
452 'extra_disconnection_errors', ())452 'extra_disconnection_errors', ())
453 try:453 try:
454 return function(*args, **kwargs)454 return function(*args, **kwargs)
455 except Exception, exc:455 except Exception as exc:
456 if self.is_disconnection_error(exc, extra_disconnection_errors):456 if self.is_disconnection_error(exc, extra_disconnection_errors):
457 self._state = STATE_DISCONNECTED457 self._state = STATE_DISCONNECTED
458 self._raw_connection = None458 self._raw_connection = None
459459
=== modified file 'storm/databases/sqlite.py'
--- storm/databases/sqlite.py 2015-06-15 12:02:12 +0000
+++ storm/databases/sqlite.py 2019-05-30 13:43:46 +0000
@@ -157,7 +157,7 @@
157 while True:157 while True:
158 try:158 try:
159 return Connection.raw_execute(self, statement, params)159 return Connection.raw_execute(self, statement, params)
160 except sqlite.OperationalError, e:160 except sqlite.OperationalError as e:
161 if str(e) != "database is locked":161 if str(e) != "database is locked":
162 raise162 raise
163 elif now() - started < self._database._timeout:163 elif now() - started < self._database._timeout:
164164
=== modified file 'storm/schema/schema.py'
--- storm/schema/schema.py 2015-01-26 09:57:25 +0000
+++ storm/schema/schema.py 2019-05-30 13:43:46 +0000
@@ -172,7 +172,7 @@
172 except SchemaMissingError:172 except SchemaMissingError:
173 # No schema at all. Create it from the ground.173 # No schema at all. Create it from the ground.
174 self.create(store)174 self.create(store)
175 except UnappliedPatchesError, error:175 except UnappliedPatchesError as error:
176 patch_applier.check_unknown()176 patch_applier.check_unknown()
177 for version in error.unapplied_versions:177 for version in error.unapplied_versions:
178 self.advance(store, version)178 self.advance(store, version)
179179
=== modified file 'storm/schema/sharding.py'
--- storm/schema/sharding.py 2014-12-28 11:51:53 +0000
+++ storm/schema/sharding.py 2019-05-30 13:43:46 +0000
@@ -101,7 +101,7 @@
101 schema.check(store)101 schema.check(store)
102 except SchemaMissingError:102 except SchemaMissingError:
103 schema.create(store)103 schema.create(store)
104 except UnappliedPatchesError, error:104 except UnappliedPatchesError as error:
105 if not unapplied_versions:105 if not unapplied_versions:
106 unapplied_versions = error.unapplied_versions106 unapplied_versions = error.unapplied_versions
107 elif unapplied_versions != error.unapplied_versions:107 elif unapplied_versions != error.unapplied_versions:
108108
=== modified file 'storm/twisted/transact.py'
--- storm/twisted/transact.py 2011-12-07 10:39:57 +0000
+++ storm/twisted/transact.py 2019-05-30 13:43:46 +0000
@@ -75,7 +75,7 @@
75 try:75 try:
76 result = function(*args, **kwargs)76 result = function(*args, **kwargs)
77 self._transaction.commit()77 self._transaction.commit()
78 except RETRIABLE_ERRORS, error:78 except RETRIABLE_ERRORS as error:
79 if isinstance(error, DisconnectionError):79 if isinstance(error, DisconnectionError):
80 # If we got a disconnection, calling rollback may not be80 # If we got a disconnection, calling rollback may not be
81 # enough because psycopg2 doesn't necessarily use the81 # enough because psycopg2 doesn't necessarily use the
8282
=== modified file 'tests/databases/base.py'
--- tests/databases/base.py 2016-03-10 12:04:01 +0000
+++ tests/databases/base.py 2019-05-30 13:43:46 +0000
@@ -344,7 +344,7 @@
344 connection2.execute("UPDATE test SET title='Title 100' "344 connection2.execute("UPDATE test SET title='Title 100' "
345 "WHERE id=10")345 "WHERE id=10")
346 connection2.commit()346 connection2.commit()
347 except OperationalError, e:347 except OperationalError as e:
348 self.assertEquals(str(e), "database is locked") # SQLite blocks348 self.assertEquals(str(e), "database is locked") # SQLite blocks
349 result = connection1.execute("SELECT title FROM test WHERE id=10")349 result = connection1.execute("SELECT title FROM test WHERE id=10")
350 self.assertEquals(result.get_one(), ("Title 10",))350 self.assertEquals(result.get_one(), ("Title 10",))
@@ -770,7 +770,7 @@
770 cursor = self.connection._raw_connection.cursor()770 cursor = self.connection._raw_connection.cursor()
771 cursor.execute("SELECT 1")771 cursor.execute("SELECT 1")
772 cursor.fetchone()772 cursor.fetchone()
773 except Error, exc:773 except Error as exc:
774 self.assertTrue(self.connection.is_disconnection_error(exc))774 self.assertTrue(self.connection.is_disconnection_error(exc))
775 else:775 else:
776 self.fail("Disconnection was not caught.")776 self.fail("Disconnection was not caught.")
@@ -779,7 +779,7 @@
779 # error when called.779 # error when called.
780 try:780 try:
781 self.connection._raw_connection.rollback()781 self.connection._raw_connection.rollback()
782 except Error, exc:782 except Error as exc:
783 self.assertTrue(self.connection.is_disconnection_error(exc))783 self.assertTrue(self.connection.is_disconnection_error(exc))
784 else:784 else:
785 self.fail("Disconnection was not raised.")785 self.fail("Disconnection was not raised.")
@@ -803,7 +803,7 @@
803 cursor = self.connection._raw_connection.cursor()803 cursor = self.connection._raw_connection.cursor()
804 cursor.execute("SELECT 1")804 cursor.execute("SELECT 1")
805 cursor.fetchone()805 cursor.fetchone()
806 except DatabaseError, exc:806 except DatabaseError as exc:
807 self.assertTrue(self.connection.is_disconnection_error(exc))807 self.assertTrue(self.connection.is_disconnection_error(exc))
808 else:808 else:
809 self.fail("Disconnection was not caught.")809 self.fail("Disconnection was not caught.")
810810
=== modified file 'tests/databases/postgres.py'
--- tests/databases/postgres.py 2016-04-29 08:38:51 +0000
+++ tests/databases/postgres.py 2019-05-30 13:43:46 +0000
@@ -741,7 +741,7 @@
741 self.connection._raw_connection = FakeConnection()741 self.connection._raw_connection = FakeConnection()
742 try:742 try:
743 self.connection.rollback()743 self.connection.rollback()
744 except Exception, exc:744 except Exception as exc:
745 self.fail('Exception should have been swallowed: %s' % repr(exc))745 self.fail('Exception should have been swallowed: %s' % repr(exc))
746746
747747
@@ -875,7 +875,7 @@
875 self.remaining_time = 0.001875 self.remaining_time = 0.001
876 try:876 try:
877 self.connection.execute(statement)877 self.connection.execute(statement)
878 except TimeoutError, e:878 except TimeoutError as e:
879 self.assertEqual("SQL server cancelled statement", e.message)879 self.assertEqual("SQL server cancelled statement", e.message)
880 self.assertEqual(statement, e.statement)880 self.assertEqual(statement, e.statement)
881 self.assertEqual((), e.params)881 self.assertEqual((), e.params)
882882
=== modified file 'tests/databases/sqlite.py'
--- tests/databases/sqlite.py 2013-05-05 10:36:13 +0000
+++ tests/databases/sqlite.py 2019-05-30 13:43:46 +0000
@@ -114,7 +114,7 @@
114 started = time.time()114 started = time.time()
115 try:115 try:
116 connection2.execute("INSERT INTO test VALUES (2)")116 connection2.execute("INSERT INTO test VALUES (2)")
117 except OperationalError, exception:117 except OperationalError as exception:
118 self.assertEquals(str(exception), "database is locked")118 self.assertEquals(str(exception), "database is locked")
119 self.assertTrue(time.time()-started >= 0.3)119 self.assertTrue(time.time()-started >= 0.3)
120 else:120 else:
@@ -141,7 +141,7 @@
141 started = time.time()141 started = time.time()
142 try:142 try:
143 connection1.commit()143 connection1.commit()
144 except OperationalError, exception:144 except OperationalError as exception:
145 self.assertEquals(str(exception), "database is locked")145 self.assertEquals(str(exception), "database is locked")
146 # In 0.10, the next assertion failed because the timeout wasn't146 # In 0.10, the next assertion failed because the timeout wasn't
147 # enforced for the "COMMIT" statement.147 # enforced for the "COMMIT" statement.
148148
=== modified file 'tests/mocker.py'
--- tests/mocker.py 2008-05-18 10:22:29 +0000
+++ tests/mocker.py 2019-05-30 13:43:46 +0000
@@ -487,7 +487,7 @@
487 for event in self._events:487 for event in self._events:
488 try:488 try:
489 event.verify()489 event.verify()
490 except AssertionError, e:490 except AssertionError as e:
491 error = str(e)491 error = str(e)
492 if not error:492 if not error:
493 raise RuntimeError("Empty error message from %r"493 raise RuntimeError("Empty error message from %r"
@@ -1029,7 +1029,7 @@
1029 path.root_object = object1029 path.root_object = object
1030 try:1030 try:
1031 return self.__mocker__.act(path)1031 return self.__mocker__.act(path)
1032 except MatchError, exception:1032 except MatchError as exception:
1033 root_mock = path.root_mock1033 root_mock = path.root_mock
1034 if (path.root_object is not None and1034 if (path.root_object is not None and
1035 root_mock.__mocker_passthrough__):1035 root_mock.__mocker_passthrough__):
@@ -1037,7 +1037,7 @@
1037 # Reinstantiate to show raise statement on traceback, and1037 # Reinstantiate to show raise statement on traceback, and
1038 # also to make the traceback shown shorter.1038 # also to make the traceback shown shorter.
1039 raise MatchError(str(exception))1039 raise MatchError(str(exception))
1040 except AssertionError, e:1040 except AssertionError as e:
1041 lines = str(e).splitlines()1041 lines = str(e).splitlines()
1042 message = [ERROR_PREFIX + "Unmet expectation:", ""]1042 message = [ERROR_PREFIX + "Unmet expectation:", ""]
1043 message.append("=> " + lines.pop(0))1043 message.append("=> " + lines.pop(0))
@@ -1083,7 +1083,7 @@
1083 # something that doesn't offer them.1083 # something that doesn't offer them.
1084 try:1084 try:
1085 result = self.__mocker_act__("len")1085 result = self.__mocker_act__("len")
1086 except MatchError, e:1086 except MatchError as e:
1087 raise AttributeError(str(e))1087 raise AttributeError(str(e))
1088 if type(result) is Mock:1088 if type(result) is Mock:
1089 return 01089 return 0
@@ -1092,7 +1092,7 @@
1092 def __nonzero__(self):1092 def __nonzero__(self):
1093 try:1093 try:
1094 return self.__mocker_act__("nonzero")1094 return self.__mocker_act__("nonzero")
1095 except MatchError, e:1095 except MatchError as e:
1096 return True1096 return True
10971097
1098 def __iter__(self):1098 def __iter__(self):
@@ -1519,7 +1519,7 @@
1519 for task in self._tasks:1519 for task in self._tasks:
1520 try:1520 try:
1521 task_result = task.run(path)1521 task_result = task.run(path)
1522 except AssertionError, e:1522 except AssertionError as e:
1523 error = str(e)1523 error = str(e)
1524 if not error:1524 if not error:
1525 raise RuntimeError("Empty error message from %r" % task)1525 raise RuntimeError("Empty error message from %r" % task)
@@ -1562,7 +1562,7 @@
1562 for task in self._tasks:1562 for task in self._tasks:
1563 try:1563 try:
1564 task.verify()1564 task.verify()
1565 except AssertionError, e:1565 except AssertionError as e:
1566 error = str(e)1566 error = str(e)
1567 if not error:1567 if not error:
1568 raise RuntimeError("Empty error message from %r" % task)1568 raise RuntimeError("Empty error message from %r" % task)
15691569
=== modified file 'tests/schema/patch.py'
--- tests/schema/patch.py 2014-12-18 10:57:52 +0000
+++ tests/schema/patch.py 2019-05-30 13:43:46 +0000
@@ -345,7 +345,7 @@
345 self.add_module("patch_999.py", patch_no_args_apply)345 self.add_module("patch_999.py", patch_no_args_apply)
346 try:346 try:
347 self.patch_applier.apply_all()347 self.patch_applier.apply_all()
348 except BadPatchError, e:348 except BadPatchError as e:
349 self.assertTrue("mypackage/patch_999.py" in str(e))349 self.assertTrue("mypackage/patch_999.py" in str(e))
350 self.assertTrue("takes no arguments" in str(e))350 self.assertTrue("takes no arguments" in str(e))
351 self.assertTrue("TypeError" in str(e))351 self.assertTrue("TypeError" in str(e))
@@ -360,7 +360,7 @@
360 self.add_module("patch_999.py", patch_missing_apply)360 self.add_module("patch_999.py", patch_missing_apply)
361 try:361 try:
362 self.patch_applier.apply_all()362 self.patch_applier.apply_all()
363 except BadPatchError, e:363 except BadPatchError as e:
364 self.assertTrue("mypackage/patch_999.py" in str(e))364 self.assertTrue("mypackage/patch_999.py" in str(e))
365 self.assertTrue("no attribute" in str(e))365 self.assertTrue("no attribute" in str(e))
366 self.assertTrue("AttributeError" in str(e))366 self.assertTrue("AttributeError" in str(e))
@@ -375,7 +375,7 @@
375 self.add_module("patch_999.py", "that's not python")375 self.add_module("patch_999.py", "that's not python")
376 try:376 try:
377 self.patch_applier.apply_all()377 self.patch_applier.apply_all()
378 except BadPatchError, e:378 except BadPatchError as e:
379 self.assertTrue(" 999 " in str(e))379 self.assertTrue(" 999 " in str(e))
380 self.assertTrue("SyntaxError" in str(e))380 self.assertTrue("SyntaxError" in str(e))
381 else:381 else:
@@ -389,7 +389,7 @@
389 self.add_module("patch_999.py", patch_name_error)389 self.add_module("patch_999.py", patch_name_error)
390 try:390 try:
391 self.patch_applier.apply_all()391 self.patch_applier.apply_all()
392 except BadPatchError, e:392 except BadPatchError as e:
393 self.assertTrue("mypackage/patch_999.py" in str(e))393 self.assertTrue("mypackage/patch_999.py" in str(e))
394 self.assertTrue("NameError" in str(e))394 self.assertTrue("NameError" in str(e))
395 self.assertTrue("blah" in str(e))395 self.assertTrue("blah" in str(e))
396396
=== modified file 'tests/store/base.py'
--- tests/store/base.py 2019-05-29 15:35:00 +0000
+++ tests/store/base.py 2019-05-30 13:43:46 +0000
@@ -5929,7 +5929,7 @@
5929 self.store.commit()5929 self.store.commit()
5930 try:5930 try:
5931 self.assertEquals(myfoo.title, title)5931 self.assertEquals(myfoo.title, title)
5932 except AssertionError, e:5932 except AssertionError as e:
5933 raise AssertionError(unicode(e, 'replace') +5933 raise AssertionError(unicode(e, 'replace') +
5934 " (ensure your database was created with CREATE DATABASE"5934 " (ensure your database was created with CREATE DATABASE"
5935 " ... CHARACTER SET utf8)")5935 " ... CHARACTER SET utf8)")
59365936
=== modified file 'tests/tracer.py'
--- tests/tracer.py 2012-06-28 14:21:49 +0000
+++ tests/tracer.py 2019-05-30 13:43:46 +0000
@@ -290,7 +290,7 @@
290290
291 try:291 try:
292 self.execute()292 self.execute()
293 except TimeoutError, e:293 except TimeoutError as e:
294 self.assertEqual("0 seconds remaining in time budget", e.message)294 self.assertEqual("0 seconds remaining in time budget", e.message)
295 self.assertEqual(self.statement, e.statement)295 self.assertEqual(self.statement, e.statement)
296 self.assertEqual(self.params, e.params)296 self.assertEqual(self.params, e.params)
@@ -662,7 +662,7 @@
662 try:662 try:
663 with CaptureTracer():663 with CaptureTracer():
664 raise RuntimeError("boom")664 raise RuntimeError("boom")
665 except RuntimeError, error:665 except RuntimeError as error:
666 errors.append(error)666 errors.append(error)
667 [error] = errors667 [error] = errors
668 self.assertEqual("boom", str(error))668 self.assertEqual("boom", str(error))
669669
=== modified file 'tests/variables.py'
--- tests/variables.py 2019-04-07 16:20:40 +0000
+++ tests/variables.py 2019-05-30 13:43:46 +0000
@@ -143,7 +143,7 @@
143 variable = CustomVariable(allow_none=False, column=column)143 variable = CustomVariable(allow_none=False, column=column)
144 try:144 try:
145 variable.set(None)145 variable.set(None)
146 except NoneError, e:146 except NoneError as e:
147 pass147 pass
148 self.assertTrue("column_name" in str(e))148 self.assertTrue("column_name" in str(e))
149149
@@ -152,7 +152,7 @@
152 variable = CustomVariable(allow_none=False, column=column)152 variable = CustomVariable(allow_none=False, column=column)
153 try:153 try:
154 variable.set(None)154 variable.set(None)
155 except NoneError, e:155 except NoneError as e:
156 pass156 pass
157 self.assertTrue("table_name.column_name" in str(e))157 self.assertTrue("table_name.column_name" in str(e))
158158
@@ -769,7 +769,7 @@
769 def test_unsupported_unit(self):769 def test_unsupported_unit(self):
770 try:770 try:
771 self.check("1 month", None)771 self.check("1 month", None)
772 except ValueError, e:772 except ValueError as e:
773 self.assertEquals(str(e), "Unsupported interval unit 'month' "773 self.assertEquals(str(e), "Unsupported interval unit 'month' "
774 "in interval '1 month'")774 "in interval '1 month'")
775 else:775 else:
@@ -778,7 +778,7 @@
778 def test_missing_value(self):778 def test_missing_value(self):
779 try:779 try:
780 self.check("day", None)780 self.check("day", None)
781 except ValueError, e:781 except ValueError as e:
782 self.assertEquals(str(e), "Expected an interval value rather than "782 self.assertEquals(str(e), "Expected an interval value rather than "
783 "'day' in interval 'day'")783 "'day' in interval 'day'")
784 else:784 else:
785785
=== modified file 'tests/zope/zstorm.py'
--- tests/zope/zstorm.py 2012-03-06 10:28:06 +0000
+++ tests/zope/zstorm.py 2019-05-30 13:43:46 +0000
@@ -355,7 +355,7 @@
355 store.execute("SELECT 1")355 store.execute("SELECT 1")
356 except ZStormError:356 except ZStormError:
357 failures.append("ZStormError raised")357 failures.append("ZStormError raised")
358 except Exception, exc:358 except Exception as exc:
359 failures.append("Expected ZStormError, got %r" % exc)359 failures.append("Expected ZStormError, got %r" % exc)
360 else:360 else:
361 failures.append("Expected ZStormError, nothing raised")361 failures.append("Expected ZStormError, nothing raised")

Subscribers

People subscribed via source and target branches

to status/vote changes: