Le jeudi 23 septembre 2010 à 19:51 +0200, Tarek Ziadé a écrit :
On Thu, Sep 23, 2010 at 6:32 PM, Antoine Pitrou <solipsis@pitrou.net> wrote: ...
This feature already exists, as you mention, using issubclass() or isinstance(). What you are asking for is a different feature: check that a class has an appropriate implementation of the advertised capabilities. Traditionally, this is best left to unit testing (or other forms of test-based checking).
Do you have an use case where unit testing would not be appropriate for this?
Why are you thinking about unit tests ? Don't you ever use issubclass/isinstance in your programs ?
Sorry, you don't seem to be answering the question. Why wouldn't the implementor of the class use unit tests to check that his/her class implements the desired ABC?
Checking signatures using ABC when you create a plugin system is one use case for instance.
Again, why do you want to check signatures? Do you not trust plugin authors to write plugins? Also, why do you think checking signatures is actually useful? It only checks that the signature is right, not that the expected semantics are observed. The argument for checking method signature in advance is as weak as the argument for checking types at compile time.
It depends on the arguments. And the implementation could definitely use *args or **kwargs arguments, especially if it acts as a proxy.
Sure but ISTM that most of the time signatures are well defined, and proxies lives in an upper layer.
Not really. If I write a file object wrapper that proxies some methods to an other file object, I don't want to re-type all method signatures (including default args) by hand. Regards Antoine.