Abstract Base Class register function

M

Mikolai Fajer

I have been experimenting with the abc module in py3k and thought
about using the register method of an ABC as a class decorator:

<code>
import abc
class MyABC(metaclass=abc.ABCMeta):
pass

@MyABC.register
class MySub():
pass
</code>

This doesn't work because the register method returns None. It would
be a fairly simple modification to have this work:

<code>
def register(cls, subclass):
"""Register a virtual subclass of an ABC."""
... etc ...
return subclass
</code>

What do people think of this behavior?
 
B

Benjamin

I have been experimenting with the abc module in py3k and thought
about using the register method of an ABC as a class decorator:

<code>
import abc
class MyABC(metaclass=abc.ABCMeta):
    pass

@MyABC.register
class MySub():
    pass
</code>

This doesn't work because the register method returns None.  It would
be a fairly simple modification to have this work:

<code>
    def register(cls, subclass):
        """Register a virtual subclass of an ABC."""
        ... etc ...
        return subclass
</code>

What do people think of this behavior?

It's probably better to just inherit from your metclass. register is
really for use with extension types that implement an interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top