Merge lp:~cjwatson/storm/lp-psycopg-2.5 into lp:~launchpad-committers/storm/lp

Proposed by Colin Watson
Status: Merged
Merged at revision: 407
Proposed branch: lp:~cjwatson/storm/lp-psycopg-2.5
Merge into: lp:~launchpad-committers/storm/lp
Diff against target: 29 lines (+9/-3)
1 file modified
storm/exceptions.py (+9/-3)
To merge this branch: bzr merge lp:~cjwatson/storm/lp-psycopg-2.5
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+278350@code.launchpad.net

Commit message

Use ABCMeta for exception base class injection

This requires Python >= 2.6 (which is unlikely to be a problem these days!),
and adds compatibility with psycopg2 >= 2.5.

Description of the change

Cherry-pick https://code.launchpad.net/~cjwatson/storm/psycopg-2.5/+merge/278330, proposed to mainline. This will let us upgrade Launchpad to psycopg2 >= 2.5, adding support for the json column type.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/exceptions.py'
2--- storm/exceptions.py 2010-10-23 21:02:22 +0000
3+++ storm/exceptions.py 2015-11-23 17:31:01 +0000
4@@ -18,10 +18,12 @@
5 # You should have received a copy of the GNU Lesser General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7 #
8+from abc import ABCMeta
9+import types
10
11
12 class StormError(Exception):
13- pass
14+ __metaclass__ = ABCMeta
15
16
17 class CompileError(StormError):
18@@ -141,5 +143,9 @@
19 OperationalError, ProgrammingError, IntegrityError,
20 DataError, NotSupportedError, InterfaceError):
21 module_exception = getattr(module, exception.__name__, None)
22- if module_exception is not None:
23- module_exception.__bases__ += (exception,)
24+ if (module_exception is not None and
25+ isinstance(module_exception, (type, types.ClassType))):
26+ # XXX This may need to be revisited when porting to Python 3 if
27+ # virtual subclasses are still ignored for exception handling
28+ # (https://bugs.python.org/issue12029).
29+ exception.register(module_exception)

Subscribers

People subscribed via source and target branches