Behaviour-based interface/protocol implementation?
Ethan Furman
ethan at stoneleaf.us
Thu Jan 27 14:58:40 EST 2011
Alan Franzoni wrote:
> Hello,
> I'd like to have a system which lets me do certain actions if the
> duck-type of a certain objects matches what I expect, i.e. I'd like to
> have a formalization of what it's sometimes done through getattr()
> calls:
>
> if getattr(myobj, "somemethod", None) is not None:
> myobj.somemethod(somevalue)
[...]
>
> I'd like to do a kind of runtime-check for signatures. Of course there
> couldn't be an absolute certainty of interface implementation, because
> a runtime dynamic proxy method (accepting *args and **kwargs in its
> signature, as an example) might just fool my signature check.
When you signature check, do you mean counting the number of arguments,
or actually checking argument types?
~Ethan~
More information about the Python-list
mailing list