On Sat, May 21, 2011 at 10:03 AM, Eric Snow <ericsnowcurrently@gmail.com> wrote:
This is a small addition, but I realize it [potentially] adds another special method to classes, so it's not trivial. The use case is that I want to be able to validate that a class implements all of the abstract methods of all the classes to which it has been registered. I don't have a programmatic way of discovering that set without asking every class out there. This is an easy way to accomplish this (for non-extension/non-builtin types). An alternative is to subclass ABCMeta and tack this on, but that only works for my ABCs. Another is to use a class decorator to do this any place I do a register (or even to do the register too), but again, only for the places that I do the registration. Anyway, if it's useful to me then it may be useful to others, so I wanted to put this out there. I expect this has come up before, particularly during discussions about PEP 3119. However, I wasn't able to track down anything specifically about doing this sort of "reverse registration". And, of course, I may be overestimating the value of this functionality. If this does not seem that valuable to anyone else, then no big deal. :)
An alternative approach to the same idea was to be able to register callbacks with ABCs to track registration and deregistration operations on that ABC and any subclasses. This has the advantage of working with arbitrary objects, including those without mutable __dict__ attributes. Such an approach would start by building a type map (via ABC.__subclasses__) and then using the callback hooks to keep the mapping up to date. I believe there is an open tracker item for that concept, but I can't currently find a reference to it. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia