Re: metaclass question

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:43 AM, Chris Withers wrote: > Hi All, > > Is there a metaclass-y way I could cause the following: > > class TheParser(Parser): > def handle_ARecord(self): > pass > def handle_ARecord(self): > pass > > ...to raise an exception as a result of the 'h

metaclass question

2012-09-24 Thread Chris Withers
Hi All, Is there a metaclass-y way I could cause the following: class TheParser(Parser): def handle_ARecord(self): pass def handle_ARecord(self): pass ...to raise an exception as a result of the 'handle_ARecord' name being reused? cheers, Chris -- Simplistix - Conte

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread BartlebyScrivener
On Sep 7, 1:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > All you really need is to create your SplinterBorgs with appropriate > group names, you don't neef subclasses at all: oops, I tried this once and the link broke. I'll try tinyurl. Dang. With that subject heading I thought this was abou

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread BartlebyScrivener
On Sep 7, 1:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > All you really need is to create your SplinterBorgs with appropriate > group names, you don't neef subclasses at all: > Dang. With that subject heading I thought this was about some post- Singularity, Python-programmed cyborgs rising up

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Carsten Haese
On Fri, 2007-09-07 at 14:54 -0600, Steven Bethard wrote: > Carsten Haese wrote: > > [slightly convoluted example...] > > I think I would probably write that as:: > [concise example...] > > That is, I don't think there's really a need for __new__ if you're using > a metaclass. Just set the instan

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Steven Bethard
Carsten Haese wrote: > Indeed, if you have an __init__ method that shouldn't see the "group" > argument, you need a metaclass after all so you can yank the "group" > argument between __new__ and __init__. The following code seems to work, > but it's making my brain hurt: > > class SplinterBorgMeta

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread André
On Sep 7, 4:00 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-09-07 at 15:54 +, André wrote: > > Unfortunately, it fails. Here's what I tried, followed by the > > traceback > > class SplinterBorg(object): > > _shared_states = {} > > def __new__(cls, *a, **k): > > g

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread André
On Sep 7, 3:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > André wrote: > > On Sep 7, 10:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > >> On Fri, 2007-09-07 at 12:31 +, André wrote: > >>> In my application, I make use of the Borg idiom, invented by Alex > >>> Martelli. > >>> class Borg(ob

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Carsten Haese
On Fri, 2007-09-07 at 15:54 +, André wrote: > Unfortunately, it fails. Here's what I tried, followed by the > traceback > class SplinterBorg(object): > _shared_states = {} > def __new__(cls, *a, **k): > group = k.pop("group","BORG") > obj = object.__new__(cls, *a, **k)

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Steve Holden
André wrote: > On Sep 7, 10:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote: >> On Fri, 2007-09-07 at 12:31 +, André wrote: >>> In my application, I make use of the Borg idiom, invented by Alex >>> Martelli. >>> class Borg(object): >>> '''Borg Idiom, from the Python Cookbook, 2nd Edition, p:

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread André
On Sep 7, 10:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-09-07 at 12:31 +, André wrote: > > In my application, I make use of the Borg idiom, invented by Alex > > Martelli. > > > class Borg(object): > > '''Borg Idiom, from the Python Cookbook, 2nd Edition, p:273 > > >

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Carsten Haese
On Fri, 2007-09-07 at 12:31 +, André wrote: > In my application, I make use of the Borg idiom, invented by Alex > Martelli. > > class Borg(object): > '''Borg Idiom, from the Python Cookbook, 2nd Edition, p:273 > > Derive a class form this; all instances of that class will share > the

Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread André
In my application, I make use of the Borg idiom, invented by Alex Martelli. class Borg(object): '''Borg Idiom, from the Python Cookbook, 2nd Edition, p:273 Derive a class form this; all instances of that class will share the same state, provided that they don't override __new__; other

Re: A newbie metaclass question

2005-05-22 Thread Steven Bethard
could ildg wrote: > When I try to learn metaclass of python by article at this place: > http://www.python.org/2.2/descrintro.html#metaclasses, > I changed the autosuper example a little as below: > > class autosuper(type): > def __init__(cls,name,bases,dict): > super(autosuper,cls).__i

Re: A newbie metaclass question

2005-05-22 Thread Peter Otten
could ildg wrote: > When I try to learn metaclass of python by article at this place: > http://www.python.org/2.2/descrintro.html#metaclasses, > I changed the autosuper example a little as below: > > class autosuper(type): > def __init__(cls,name,bases,dict): > super(autosuper,cls).__

Re: A newbie metaclass question

2005-05-22 Thread Michele Simionato
There are many resources for metaclasses on the Net. There was a Wiki page on www.python.org about them, but I don't find it now. So, I will refer you to the links I have handy: http://www-106.ibm.com/developerworks/linux/library/l-pymeta.html http://www-128.ibm.com/developerworks/linux/library/l-

A newbie metaclass question

2005-05-22 Thread could ildg
When I try to learn metaclass of python by article at this place: http://www.python.org/2.2/descrintro.html#metaclasses, I changed the autosuper example a little as below: class autosuper(type): def __init__(cls,name,bases,dict): super(autosuper,cls).__init__(name,bases,dict) s