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

Georg Brandl g.brandl at gmx.net
Fri Sep 24 09:15:00 CEST 2010


Am 23.09.2010 16:37, schrieb Tarek Ziadé:
> 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.

I'm not concerned about this in the least.  Whoever implements a special
method with the wrong signature has more pressing problems than a false-
positive ABC subclass check.  And AFAIK, our ABCs only check for special
methods.

> 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.

"ordering"?

Georg


-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list