My quarterly question on Design by Contract in Python...

Tim Peters tim_one at email.msn.com
Sat May 8 03:34:58 EDT 1999


[Stuart Hungerford]
> Every so often after a minor or major Python
> release I like to ask the gurus of this group
> about implementing Design By Contract mechanisms
> (a-la Eiffel) in Python.

And if everything runs true to form, they'll leave the question unanswered
for a week, at which point I'll jump in to rekindle the illusion that
someone has been taking this seriously <wink>.

> Has anything changed in the 1.5.x releases that
> would make doing this any harder or easier? Have
> experiences with the Extension class stuff shown
> any new insights?

The good news is that, as of 1.5.2, "assert" has still not been removed from
the language.  Other than that, though, no.  Well, yes:  you can assign to a
class's __bases__ attribute now, so Python is even more dynamic than it was,
dashing all hope of capturing any of the class hierarchy at compile-time.

> I'm not trying to turn Python into Eiffel, but
> even a partial DBC implementation would be
> very useful.
>
> Please be gentle,

There's a large bed of feathers waiting for you in Python's Types-SIG.  My
guess is that automated-- or efficiently automatable --DBC's only realistic
hope rides on Python2.  Slicker metaprogramming of all kinds is a Python2
goal, and even more interesting than building DBC into the language would be
building a core "type system" on top of which DBC could be built via
metaprogramming magic.

finally-found-a-use-for-curly-braces<wink>-ly y'rs  - tim






More information about the Python-list mailing list