Abstract Base Class register function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikolai Fajer

    Abstract Base Class register function

    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?

    --

    -Mikolai Fajer-
  • Benjamin

    #2
    Re: Abstract Base Class register function

    On Sep 27, 4:50 pm, "Mikolai Fajer" <mfa...@gmail.c omwrote:
    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.
    >
    --
    >
         -Mikolai Fajer-

    Comment

    Working...