[PEAK] Declaration of method decorators in protocols.Interface

fifi fifi at rt.sk
Thu Mar 16 13:35:32 EST 2006


Is it possible to declare decorators of methods for interfaces? My point is 
that the decorators, such as returns, accepts,.. would be declared on one 
place and all classes implementing the interface would also aquire the 
decorators.

A simple example:

class IFoo(protocols.Interfaces):

	@returns(int)
	def hop():
		"Method returning integer"

class FooImplementation():

    protocols.advise(\
        instancesProvide = [IFoo])

    def hop():
	return 7


class BadFooImplementation():

    protocols.advise(\
        instancesProvide = [IFoo])

    def hop():
	return 7.0

As the implementations acquire the decorators from the interface. The 
FooImplementation and BadFooImplementation would behave this way:

$ f = FooImplementation()
$ f.hop()
7
$ f_bad = BadFooImplementation()
$ f_bad.hop()
ERROR: decorator expected an int value

Is it possible to do somehow? I don't mean to do it exactly in the way 
described above, however it would be nice. I would like to declare 
typecheckings at one place only.

Gyuri



More information about the PEAK mailing list