[Python-3000] Need help completing ABC pep

Talin talin at acm.org
Sat Apr 21 22:51:57 CEST 2007


John Reese wrote:
> "This PEP proposes a particular strategy for organizing these tests
> known as Abstract Base Classes, or ABC. ABCs are simply Python classes
> that are added into an object's inheritance tree to signal certain
> features of that object to an external inspector. Tests are done using
> isinstance(), and the presence of a particular ABC means that the test
> has passed."
> 
> I'd like to see another few lines in the rationale section explaining
> the intent of the concrete methods.  For example, inheriting from
> abc.Mapping would have a similar effect to inheriting from
> UserDict.DictMixin -- by overriding it's few abstract methods you get
> close to the full complement of dict's convenience methods.  But from
> the open issues and other discussion in this thread, I don't think the
> intention is to provide full coverage of the convenience methods in
> all of the builtin classes in their corresponding ABCs, but merely to
> expand the number of methods you can assume given an ABC.
> 
> I'd like an explanation of exactly where the line is being drawn in
> terms of what convenience methods ABCs will provide through concrete
> methods.

OK how about this. Replace the paragraph immediately following the one 
you quote with these two paragraphs:

In addition, the ABCs define a minimal set of methods that establish the 
characteristic behavior of the type. Code that discriminates objects 
based on their ABC type can trust that those methods will always be 
present. Each of these methods are accompanied by an generalized 
abstract semantic definition that is described in the documentation for 
the ABC. These standard semantic definitions are not enforced, but are 
strongly recommended.

Like all other things in Python, these promises are in the nature of a 
gentlemen's agreement, which in this case means that while the language 
does enforce some of the promises made in the ABC, it is up to the 
implementer of the concrete class to insure that the remaining ones are 
kept.

-- Talin



More information about the Python-3000 mailing list