Re: Code design for a sub-class of built-ins

2006-07-05 Thread Steven D'Aprano
On Wed, 05 Jul 2006 11:41:47 +0200, Bruno Desthuilliers wrote: > Steven D'Aprano wrote: >> On Tue, 04 Jul 2006 19:26:36 +0200, Bruno Desthuilliers wrote: >> >> >>>Steven D'Aprano wrote: >>> I'm having problems with sub-classes of built-in types. Here is a contrived example of my sub

Re: Code design for a sub-class of built-ins

2006-07-05 Thread Steven D'Aprano
On Tue, 04 Jul 2006 16:41:38 -0700, Alex Martelli wrote: > As others already suggested, automating such decoration is pretty easy; > you can do it with either a custom metaclass or a simple post-processing > of your class in a loop. Untested details below, but the general idea > would be somethin

Re: Code design for a sub-class of built-ins

2006-07-05 Thread Bruno Desthuilliers
Steven D'Aprano wrote: > On Tue, 04 Jul 2006 19:26:36 +0200, Bruno Desthuilliers wrote: > > >>Steven D'Aprano wrote: >> >>>I'm having problems with sub-classes of built-in types. >>> >>>Here is a contrived example of my subclass. It isn't supposed >>>to be practical, useful code, but it illustrat

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
On Tue, 04 Jul 2006 18:25:14 +, Dennis Lee Bieber wrote: > I suspect what you really want (I'm not going to open an interpreter > to test) is: > > def __init__(self, value, extra=None): > int.__init__(self, value) Yes, that's exactly what I meant -- it was a copy-an

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
On Tue, 04 Jul 2006 19:26:36 +0200, Bruno Desthuilliers wrote: > Steven D'Aprano wrote: >> I'm having problems with sub-classes of built-in types. >> >> Here is a contrived example of my subclass. It isn't supposed >> to be practical, useful code, but it illustrates my problem. >> >> class MyStr

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: ... > The obvious problem is, I have to create a custom method for every string > method -- and if strings gain any new methods in some future version of > Python, my subclass won't exhibit the correct behaviour. As others already suggested, automating

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Bruno Desthuilliers
Steven D'Aprano wrote: > I'm having problems with sub-classes of built-in types. > > Here is a contrived example of my subclass. It isn't supposed > to be practical, useful code, but it illustrates my problem. > > class MyStr(str): > """Just like ordinary strings, except it exhibits special b

Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
I'm having problems with sub-classes of built-in types. Here is a contrived example of my subclass. It isn't supposed to be practical, useful code, but it illustrates my problem. class MyStr(str): """Just like ordinary strings, except it exhibits special behaviour for one particular value