Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Abstract Base Class register function

Reply
Thread Tools

Abstract Base Class register function

 
 
Mikolai Fajer
Guest
Posts: n/a
 
      09-27-2008
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-
 
Reply With Quote
 
 
 
 
Benjamin
Guest
Posts: n/a
 
      09-28-2008
On Sep 27, 4:50*pm, "Mikolai Fajer" <mfa...@gmail.com> 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-


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
abstract base class containing class scg_ C++ 6 02-03-2009 04:50 PM
what is the difference between abstract class and pure abstract class? skishorev@yahoo.co.in C++ 4 05-17-2006 08:07 AM
About abstract class and abstract method Sameer Java 4 08-31-2005 12:59 AM
Deriving abstract class from non-abstract class Matthias Kaeppler Java 1 05-22-2005 01:28 PM
Abstract class with no abstract functions Uzytkownik C++ 3 04-03-2005 05:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57