On 4/22/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > This is worth thinking about. Recently when pondering the > question of when it would or would not be appropriate to > put in type assertions to help catch bugs, I concluded > that it makes the most sense to do so when building a > data structure, but not when just passing things around > between calls. > > The most difficult-to-debug type errors are the ones > where you've put something of the wrong type into a > data structure, and it's sat there for a while not > causing any obvious problem until something else > tries to use it, by which time most evidence of where > it came from is gone.
Inspired by this post, I've implemented this functionality in my typecheck package[1]. Traditionally, the package has offered only decorator-based type assertions for a function's arguments and return values and a generator's yield values. To complement this, I've coded up an assert_type function that's intended to be used just as Greg has described. Documentation for assert_type is available[2] from the project's website, as is a tarball of the latest SVN revision[3] (assert_type will go into the upcoming 0.4 release) so all interested parties can play around with this. [1] - http://oakwinter.com/code/typecheck/ [2] - http://oakwinter.com/code/typecheck/dev/tutorial/assert_type.html [3] - http://oakwinter.com/code/typecheck/dist/typecheck-svn-latest.tar.gz Collin Winter _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com