Re: pre-PEP generic objects

2004-12-07 Thread Jacek Generowicz
Carlos Ribeiro <[EMAIL PROTECTED]> writes: > On 06 Dec 2004 10:09:25 +0100, Jacek Generowicz > <[EMAIL PROTECTED]> wrote: > [great explanation about function descriptors] > > Thanks. Now I know more about function descriptors than I ever wanted > to :-) With a little polish, Yeah, replace the tw

Re: pre-PEP generic objects

2004-12-06 Thread Carlos Ribeiro
On 06 Dec 2004 10:09:25 +0100, Jacek Generowicz <[EMAIL PROTECTED]> wrote: [great explanation about function descriptors] Thanks. Now I know more about function descriptors than I ever wanted to :-) With a little polish, this post would make a great addition to the descriptors documentation, don't

Re: pre-PEP generic objects

2004-12-06 Thread Jacek Generowicz
Jp Calderone <[EMAIL PROTECTED]> writes: > When the class object is created, the namespace is scanned for > instances of . For those and only those, a > descriptor is created which will produce bound and unbound methods. This isn't quite correct. A descriptior is any object which has callable at

Re: pre-PEP generic objects

2004-12-04 Thread Ian Bicking
Steven Bethard wrote: Ian Bicking wrote: class bunch(object): def __init__(self, **kw): for name, value in kw.items(): # IMPORTANT! This is subclass friendly: updating __dict__ # is not! setattr(self, name, value) Good point about being subclass fri

Re: pre-PEP generic objects

2004-12-04 Thread Steven Bethard
Istvan Albert wrote: but what are you saying? that a man cannot exaggerate and fudge the facts in order to embellish his argument? :-) Heh heh. Yeah, something like that. ;) Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-12-03 Thread Istvan Albert
Steven Bethard wrote: module) not to the __builtins__. I don't see how this "litters the standard namespace". Maybe then it doesn't. but what are you saying? that a man cannot exaggerate and fudge the facts in order to embellish his argument? :-) Istvan. -- http://mail.python.org/mailman/listinfo

Re: pre-PEP generic objects

2004-12-03 Thread Steven Bethard
Ian Bicking wrote: class bunch(object): def __init__(self, **kw): for name, value in kw.items(): # IMPORTANT! This is subclass friendly: updating __dict__ # is not! setattr(self, name, value) Good point about being subclass friendly... I wonder if t

Re: pre-PEP generic objects

2004-12-03 Thread Steven Bethard
Istvan Albert wrote: On the other hand, it would be nice to have a module that implements various design patterns. The Bunch, the Borg, the Null, the Proxy all nicely documented tucked away in their separate module. That would feel a lot less like littering the standard name space with an class tha

Re: pre-PEP generic objects

2004-12-03 Thread Ian Bicking
Istvan Albert wrote: Steven Bethard wrote: > The question is not how easy it is to write, > but how many times it's going to get written. but with that logic we could create a standard "looping" construct called loop(x) that would stand in for for i in range(x): IMHO, that example is quite the o

Re: pre-PEP generic objects

2004-12-03 Thread Carlos Ribeiro
On Fri, 03 Dec 2004 08:58:48 -0500, Istvan Albert <[EMAIL PROTECTED]> wrote: > On the other hand, it would be nice to have a module that > implements various design patterns. The Bunch, the Borg, the Null, > the Proxy all nicely documented tucked away in their separate > module. That would feel a l

Re: pre-PEP generic objects

2004-12-03 Thread Remy Blank
Istvan Albert wrote: > On the other hand, it would be nice to have a module that > implements various design patterns. The Bunch, the Borg, the Null, > the Proxy all nicely documented tucked away in their separate > module. That would feel a lot less like littering the standard name space > with an

Re: pre-PEP generic objects

2004-12-03 Thread Istvan Albert
Steven Bethard wrote: > The question is not how easy it is to write, > but how many times it's going to get written. but with that logic we could create a standard "looping" construct called loop(x) that would stand in for for i in range(x): or a file_reader('whatever') generator that would be a s

Re: pre-PEP generic objects

2004-12-03 Thread Carlos Ribeiro
On Fri, 03 Dec 2004 07:41:59 -0500, Steve Holden <[EMAIL PROTECTED]> wrote: > Next question: bunch is a cute name, but not very suggestive of purpose. > Who can think of a better one? "Better"is highly subjective in this context. There are several alternatives: Bunch Generic Record DataRecord I

Re: pre-PEP generic objects

2004-12-03 Thread Steve Holden
Paul Rubin wrote: Steven Bethard <[EMAIL PROTECTED]> writes: IMHO this too easy to accomplish right now to warrant an "official" implementation: class Bunch: pass b = Bunch() b.one, b.two, b.three = 1,2,3 works just fine, depending on the problem I might add a few special operators. For anything

Re: pre-PEP generic objects

2004-12-03 Thread Nick Craig-Wood
Peter Otten wrote: > Functions written in Python have a __get__ attribute while builtin > functions (implemented in C) don't. Python-coded functions therefore > automatically act as descriptors while builtins are just another > attribute. Jp Calderone <[EMAIL PROTECTED]> wrote: > When the class ob

Re: pre-PEP generic objects

2004-12-02 Thread Paul Rubin
Steven Bethard <[EMAIL PROTECTED]> writes: > > IMHO this too easy to accomplish right now to warrant > > an "official" implementation: > > class Bunch: > > pass > > b = Bunch() > > b.one, b.two, b.three = 1,2,3 > > works just fine, depending on the problem I might add a few special > > operator

Re: pre-PEP generic objects

2004-12-02 Thread Steven Bethard
Istvan Albert wrote: Steven Bethard wrote: I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appreciated! IMHO this to

Re: pre-PEP generic objects

2004-12-02 Thread Istvan Albert
Steven Bethard wrote: I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appreciated! IMHO this too easy to accomplish r

Re: pre-PEP generic objects

2004-12-02 Thread Jp Calderone
On Thu, 02 Dec 2004 12:26:31 -0800, Scott David Daniels <[EMAIL PROTECTED]> wrote: >Nick Craig-Wood wrote: > > Scott David Daniels <[EMAIL PROTECTED]> wrote: > >> You can simplify this: > >> class Hash(object): > >> def __init__(self, **kwargs): > >> for key,value in kwargs.items():

Re: pre-PEP generic objects

2004-12-02 Thread Scott David Daniels
Nick Craig-Wood wrote: Scott David Daniels <[EMAIL PROTECTED]> wrote: You can simplify this: class Hash(object): def __init__(self, **kwargs): for key,value in kwargs.items(): setattr(self, key, value) __getitem__ = getattr __setitem__ = setattr That doesn't wor

Re: pre-PEP generic objects

2004-12-02 Thread Peter Otten
Nick Craig-Wood wrote: > Scott David Daniels <[EMAIL PROTECTED]> wrote: >> Nick Craig-Wood wrote: >> > class Hash: >> > def __init__(self, **kwargs): >> > for key,value in kwargs.items(): >> > setattr(self, key, value) >> > def __getitem__(self, x): >> > return

Re: pre-PEP generic objects

2004-12-02 Thread Nick Craig-Wood
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > class Hash: > > def __init__(self, **kwargs): > > for key,value in kwargs.items(): > > setattr(self, key, value) > > def __getitem__(self, x): > > return getattr(self, x) > > def __s

Re: pre-PEP generic objects

2004-12-01 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Steven Bethard <[EMAIL PROTECTED]> wrote: > > > >> I promised I'd put together a PEP for a 'generic object' data type for > >> Python 2.5 that allows one to replace __getitem__ style access with > >> dotted-attribute style a

assymetry between a == b and a.__eq__(b) (WAS: pre-PEP generic objects)

2004-12-01 Thread Steven Bethard
Peter Otten wrote: Steven Bethard wrote: def __eq__(self, other): """x.__eq__(y) <==> x == y""" return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__) This results in an asymmetry: from bunch import Bunch class B(Bunch): pass ... B().__eq__(Bunch()) False B

Re: pre-PEP generic objects

2004-12-01 Thread Peter Otten
Steven Bethard wrote: > Peter Otten wrote: >> Steven Bethard wrote: >> >>>def __eq__(self, other): >>>"""x.__eq__(y) <==> x == y""" >>>return (isinstance(other, self.__class__) >>>and self.__dict__ == other.__dict__) >> >> This results in an asymmetry: >> > [snip] >> >> Whe

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Jp Calderone wrote: One thing I notice with both of these versions: >>> Hash(self=10) Traceback (most recent call last): File "", line 1, in ? TypeError: __init__() got multiple values for keyword argument 'self' Good call. I've adjusted my methods to look like: def __init_

Re: pre-PEP generic objects

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 17:52:33 -0500, =?iso-8859-1?Q?Fran=E7ois?= Pinard <[EMAIL PROTECTED]> wrote: >[Scott David Daniels] > > > You can simplify this: > > class Hash(object): > > def __init__(self, **kwargs): > > for key,value in kwargs.items(): > > setattr(self, key, value

Re: pre-PEP generic objects

2004-11-30 Thread François Pinard
[Scott David Daniels] > You can simplify this: > class Hash(object): > def __init__(self, **kwargs): > for key,value in kwargs.items(): > setattr(self, key, value) Might it be: def __init__(self, **kwargs): self.__dict__.update(kwargs) -- François Pinard h

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Scott David Daniels wrote: Nick Craig-Wood wrote: class Hash: def __init__(self, **kwargs): for key,value in kwargs.items(): setattr(self, key, value) def __getitem__(self, x): return getattr(self, x) def __setitem__(self, x, y): setattr(self, x, y)

Re: pre-PEP generic objects

2004-11-30 Thread Scott David Daniels
Nick Craig-Wood wrote: class Hash: def __init__(self, **kwargs): for key,value in kwargs.items(): setattr(self, key, value) def __getitem__(self, x): return getattr(self, x) def __setitem__(self, x, y): setattr(self, x, y) You can simplify this: class

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Nick Coghlan wrote: The proposed use cases sound more appropriate for a "named tuple" than any sort of dictionary. (This may have been mentioned in previous discussions. I wasn't keeping track of those, though) For the return values, yeah, a "named tuple" is probably at least as appropriate. I'

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Nick Craig-Wood wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appr

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Peter Otten wrote: Steven Bethard wrote: def __eq__(self, other): """x.__eq__(y) <==> x == y""" return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__) This results in an asymmetry: [snip] Whether this is intended, I don't know. If someone can enlighten me...

Re: pre-PEP generic objects

2004-11-30 Thread Steven Bethard
Fredrik Lundh wrote: Steven Bethard wrote: Currently, if a Python programmer makes this design decision, they are forced to declare a new class, and then build instances of this class. FORCED to create a new class, and FORCED to create instances of their own class instead of your class? I don't see

Re: pre-PEP generic objects

2004-11-30 Thread Carlos Ribeiro
On Tue, 30 Nov 2004 22:30:21 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: > The proposed use cases sound more appropriate for a "named tuple" than any > sort > of dictionary. (This may have been mentioned in previous discussions. I wasn't > keeping track of those, though) I agree with it. I was

Re: pre-PEP generic objects

2004-11-30 Thread Nick Coghlan
The proposed use cases sound more appropriate for a "named tuple" than any sort of dictionary. (This may have been mentioned in previous discussions. I wasn't keeping track of those, though) Notice that I've used 'fromPairs' rather than 'fromMapping', since consistent order matters for a tuple.

Re: pre-PEP generic objects

2004-11-30 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote: > I promised I'd put together a PEP for a 'generic object' data type for > Python 2.5 that allows one to replace __getitem__ style access with > dotted-attribute style access (without declaring another class). Any > comments would be appreciated! T

Re: pre-PEP generic objects

2004-11-30 Thread Peter Otten
Steven Bethard wrote: > def __eq__(self, other): > """x.__eq__(y) <==> x == y""" > return (isinstance(other, self.__class__) > and self.__dict__ == other.__dict__) This results in an asymmetry: >>> from bunch import Bunch >>> class B(Bunch): pass ... >>> B().__eq__(Bunch()) F

Re: pre-PEP generic objects

2004-11-30 Thread Fredrik Lundh
Steven Bethard wrote: > Currently, if a Python programmer makes this design decision, they are > forced to declare a new class, and then build instances of this class. FORCED to create a new class, and FORCED to create instances of their own class instead of your class? without this, Python must

pre-PEP generic objects

2004-11-29 Thread Steven Bethard
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appreciated! Thanks! Steve -