ABCMeta.register is great. It adds the cls argument to the _abc_registry of the ABC. However, the class that was passed in does not get touched. If you then want to find out to which classes a class has been registered, you can't find out from that class. Whereas your can find out from an abstract base class which classes have been registered to it.<div>
<br></div><div>I propose having ABCMeta.register add/update a special method __implements__ to the class that is getting registered. This would not be done to builtin/extension types. It adds the ABC to the __implements__ of the subclass that is getting registered. Something along these lines, right before the final return in the method:</div>
<div><br></div><div><div> if not hasattr(subclass, "__implements__"):</div><div> try:</div><div> subclass.__implements__ = {cls}</div><div> except TypeError:</div><div>
pass</div><div> else:</div><div> subclass.__implements__.add(cls)</div></div><div><br></div><div>This is a small addition, but I realize it [potentially] adds another special method to classes, so it's not trivial.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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. :)</div>
<div><br></div><div>-eric</div>