[Python-ideas] ABC: what about the method arguments ?

Tarek Ziadé ziade.tarek at gmail.com
Thu Sep 23 16:37:21 CEST 2010


Hello,

ABC __subclasshook__ implementations will only check that the method
is present in the class. That's the case for example in
collections.Container. It will check that the __contains__ method is
present but that's it. It won't check that the method has only one
argument. e.g. __contains__(self, x)

The problem is that the implemented method could have a different list
of arguments and will eventually fail.

Using inspect, we could check in __subclasshook__ that the arguments
defined are the same than the ones defined in the abstractmethod.--
the name and the ordering.

I can even think of a small function in ABC for that:
same_signature(method1, method2) => True or False

Regards
Tarek

-- 
Tarek Ziadé | http://ziade.org



More information about the Python-ideas mailing list