GNOME Bugzilla – Bug 341114
pygst.require uses asserts rather than real error checking
Last modified: 2006-06-09 17:21:46 UTC
+++ This bug was initially created as a clone of Bug #341113 +++ pygst.require uses the assert keyword to check if the requested version is available, and doesn't conflict with a previous requested one. However, assert statements in Python are stripped when using python -O, and so can't be used for real run-time sanity checks. They should be replaced by conditionals that raise appropriate error types (probably ValueError, or a custom subclass of it). Example: piman@toybox:~$ python -O Python 2.3.5 (#2, Mar 6 2006, 10:12:24) [GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gst >>> import pygst >>> pygst.require("0.8") >>> pygst.require("0.10") >>>
what does pygtk do for this ?
The bug this one was cloned from (#341113) is the same thing for pygtk. I'll chat with Johan about the implications.
If there's some concern for API compatibility (though note the previous API was unreliably broken in the first place), the error raised could be a subclass of both ValueError and AssertionError. Then both the new except ValueError: and the old except AssertionError: would catch the issue.
Created attachment 65342 [details] [review] Raise a custom. compatible error explicitly, rather than using assert.
cvs version was already raising a AssertionError, but your patch is cleaner and more compatible. Commited to cvs. 2006-06-09 Edward Hervey <edward@fluendo.com> * pygst.py.in: Raise RequiredVersionError(ValueError, AssertionError) wherever applicable. This makes the new system (raising an error) compatible with the old system (assertions). Fixes #341114