Abstract Base Class register function

Discussion in 'Python' started by Mikolai Fajer, Sep 27, 2008.

  1. 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-
    Mikolai Fajer, Sep 27, 2008
    #1
    1. Advertising

  2. Mikolai Fajer

    Benjamin Guest

    On Sep 27, 4:50 pm, "Mikolai Fajer" <> wrote:
    > 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-
    Benjamin, Sep 28, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Kaeppler
    Replies:
    1
    Views:
    420
    R.F. Pels
    May 22, 2005
  2. Sameer
    Replies:
    4
    Views:
    573
    Roedy Green
    Aug 31, 2005
  3. Uzytkownik
    Replies:
    3
    Views:
    578
    Uzytkownik
    Apr 3, 2005
  4. Iyer, Prasad C

    Abstract Methods & Abstract Class

    Iyer, Prasad C, Oct 20, 2005, in forum: Python
    Replies:
    0
    Views:
    527
    Iyer, Prasad C
    Oct 20, 2005
  5. Replies:
    4
    Views:
    801
    Rolf Magnus
    May 17, 2006
Loading...

Share This Page