[Python-ideas] ABC: what about the method arguments ? (original) (raw)

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