Can __abstractmethods__ be made documented/public?

ABCs define an __abstractmethods__ frozenset which is computed at class definition time and lists the methods which are abstract.

It’s not in the docs but I recently had cause[1] to go spelunking in a class __new__ to look at this data. You can compute it yourself and the docs contain __abstractmethod__ as an attribute of decorated methods. But it’s already being built for you by ABCMeta, so why not use that instead of recomputing?

I don’t think the implementation has changed significantly in years. Would there be anything wrong with documenting this set, and committing to it as part of the contract around ABCs?


  1. an abstract class which inherits from dict, not sure if it’s a good idea but maybe a little besides the point ↩︎

2 Likes

I know I’ve personally “accepted the risk” by using it before even though it was undocumented

Was doing some dynamic class nonsense that added things after classes had been defined (to deal with forward references, kind of similar to an ORM) and checked against __abstractmethods__

It seems like one of those things that even though it’s private, it’s a straightforward enough implementation that has been consistent for so long, it’s probably not going to change