Hooks, aspect-oriented programming, and design by contract
pedro_rodriguez at club-internet.fr
Tue Jan 22 12:27:02 EST 2002
"Gustavo Niemeyer" <niemeyer at conectiva.com> wrote:
>> maybe I'm just reinventing the wheel, but I just noted that Alex's
>> Aspecter function can easily be twitched to enforce some kind of design
>> by contract (which of course can be considered an aspect). Here's my
>> first shot at it. Corrections and improvements are much welcome.
> Here is some code I've written to play around with metaclasses. It may
> give you some ideas.
<code snipped for brievety>
How do you set up an attributes in your classes ???
How should a class be initialized ?
Notice that :
- 'print 1' is not executed,
- A is ContractMeta object,
- a is a ContractInstance
Shouldn't there be an initialisation function to be called
when creating a ContractInstance ?
The following extension from your exemple fails because 'x' is not found.
if __name__ == "__main__":
# Usage example
def __init__(self, *args):
self.x = 0
assert self.x == 0
self.x = 1
def a_post(self, result):
a = A()
More information about the Python-list