Use ABCMeta for storm.exceptions?
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
Fix Released
|
Undecided
|
Colin Watson |
Bug Description
In order to make error handling easier in storm.django, I filed https:/
I had suggested a scheme similar to what we use with the Storm exceptions where we patch them into the inheritance hierarchy of the database adapter's existing exceptions. This didn't go over too well, and I had a second idea on how to achieve this using the abc module added in Python 2.6.
It lets us achieve a similar effect without patching __bases__. For instance:
import abc
class MyException(
MyException
try:
1/0
except MyException:
print "Caught ZeroDivisionError with MyException"
Perhaps it would be cleaner if we did the same sort of thing in Storm?
It currently has some problems with Python 3.2 (see http://
Related branches
- Björn Tillenius (community): Approve
- Adam Collard (community): Approve
-
Diff: 29 lines (+9/-3)1 file modifiedstorm/exceptions.py (+9/-3)
- Simon Poirier (community): Approve
-
Diff: 423 lines (+228/-31)6 files modifiedNEWS (+4/-0)
storm/database.py (+132/-1)
storm/databases/postgres.py (+28/-7)
storm/databases/sqlite.py (+15/-9)
storm/exceptions.py (+46/-14)
tests/database.py (+3/-0)
Changed in storm: | |
milestone: | none → 0.21 |
Changed in storm: | |
status: | Fix Committed → Fix Released |
I took the ABCMeta approach in the branch I landed in 2016. Now I've merged a further refactoring to re-raise exceptions with diamond-inheritance exception types so that both "except <dbapi type>" and "except StormError" (etc.) keep working, while making things work in Python 3. This is somewhat like what Django ended up with after extensive discussion though with Storm-appropriate backward compatibility, and it's the best I've been able to come up with; some careful wrapper classes and context managers make the required boilerplate quite tolerable.