ABC question: what is the purpose of the register() method?

Benjamin musiccomposition at gmail.com
Sat Jun 7 23:09:45 EDT 2008


On Jun 7, 1:37 pm, Kay Schluehr <kay.schlu... at gmx.net> wrote:
> I was reading PEP 3119 (http://www.python.org/dev/peps/pep-3119/) and
> have done some experiments using Python 3.0a5. Now I'm somewhat
> puzzled about the purpose of the ABCMeta.register() method.
>
> One can use the register() method to register any class as a virtual
> subclass of any ABC. For example one can register `int` on `Iterable`
> and therefore it is a subclass which is confirmed in the issubclass
> check. What is that good for?

It's mostly good for types created in C, where it's hard to inherit a
class. For example, builtin types register them selves under some ABCs
in collections.



More information about the Python-list mailing list