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

Antoine Pitrou solipsis at pitrou.net
Thu Sep 23 18:32:49 CEST 2010

Le jeudi 23 septembre 2010 à 18:18 +0200, Tarek Ziadé a écrit :
> >> 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 don't think we should steer in the type checking direction.
> > After all, the Python philosophy of dynamicity (dynamism?) is
> > articulated around the idea that checking types "ahead of time" is
> > useless. IMO, ABCs should be used more as a convention for documenting
> > what capabilities a class claims to expose, than for type checking.
> I think it goes further than documentation at this point. ABC is
> present and used in the stdlib, not the doc.
> So asking a class about its capabilities is a feature we provide for
> third-party code.

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

> > (also, you'll have a hard time checking methods with *args or **kwargs
> > parameters)
> True, but I don't expect the ABC to define abstract methods with vague
> arguments.

It depends on the arguments. And the implementation could definitely use
*args or **kwargs arguments, especially if it acts as a proxy.



More information about the Python-ideas mailing list