Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Neal Norwitz
On 3/31/06, Alex Martelli <[EMAIL PROTECTED]> wrote: > > So, the fact that (say) Eby or Martelli or the Twisted folks or the > Zope folks like adaptation, and Ewing or Bicking or (etc ec) dislike > it, is really a side show. The point that matters, instead, is > whether GvR likes it or not. From my

[Python-3000] Iterating over a dict

2006-04-01 Thread Thomas Lotze
Hi, I wonder what's the reason for iterating over a dict by keys: >>> for x in {1:"a", 2:"b"}: ... print x ... 1 2 I find it much more intuitive for the values, "a" and "b", to be accessed. This is particularly confusing as iterating over tuples, lists and sets in the same way does access t

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Benji York
Alex Martelli <[EMAIL PROTECTED]> wrote: > Consider __index__, and a user of gmpy, Jim Jewett wrote: > So the adaptation would be > > def gmpy_mpz_index(self): > return long(self) > gmpy.mpz.__index__=gmpy_mpz_index > > Monkeypatching someone else's class may not be pretty, but a

Re: [Python-3000] Iterating over a dict

2006-04-01 Thread Benji York
Thomas Lotze wrote: > Hi, > > I wonder what's the reason for iterating over a dict by keys: I suspect that at least part of the reason is that given a key you can easily get the corresponding value, but given the value it's difficult to get the key. Seems like a good choice for "bare" dict ite

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-04-01 Thread Benji York
Greg Ewing wrote: > Paul Moore wrote: >>The "traditional" solution, __index__, requires co-operation >>from all classes that want to support the new protocol. Adaptation >>doesn't - it can be added externally. > > I don't follow that. Adaptation only works if the > framework author has thought to

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-04-01 Thread Benji York
Greg Ewing wrote: > Benji York wrote: >>If I, as the user of the interface, have something I want to >>pass in that doesn't match I it to the appropriate interface the burden >>is on me to create something that matches expectations. People do that >>all the time today without an interface/adapt

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Aahz
On Fri, Mar 31, 2006, Alex Martelli wrote: > > Once in a while, I'm moved to sing this refrain again, but thanks to > the ensuing discussion I'm soon reminded that there are many more > gratifying activities I could pursue instead -- repeated beating of > my forehead against suitable brick wa

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Benji York
Aahz wrote: > On Fri, Mar 31, 2006, Alex Martelli wrote: > >>Once in a while, I'm moved to sing this refrain again, but thanks to >>the ensuing discussion I'm soon reminded that there are many more >>gratifying activities I could pursue instead -- repeated beating of >>my forehead against su

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Alex Martelli
On Apr 1, 2006, at 8:31 AM, Aahz wrote: ... > Seriously, I can almost see why you think adaptation is a huge > gain, but > every time I start looking closer, I get bogged down in trying to > understand adaptation registration. Do you have a simple way of > explaining how that works *well* a

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Tim Hochberg
Benji York wrote: > Aahz wrote: > >>On Fri, Mar 31, 2006, Alex Martelli wrote: >> >> >>>Once in a while, I'm moved to sing this refrain again, but thanks to >>>the ensuing discussion I'm soon reminded that there are many more >>>gratifying activities I could pursue instead -- repeated beating

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Tim Hochberg
Alex Martelli wrote: [SNIP a bunch or erudite stuff.] > > > Here is a simple reference implementation of adaptation under all of > these simplifying assumptions: > > _global_registry = {} > > def register_adapter(T, P, A, registry=_global_registry): > registry[T, P] = A > > def adapt(t

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Paul Moore
On 4/1/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > Bah! This is why adapters never get anywhere. My eyes glazed over 10 > lines ago. At their core, adapters seem like a simple enough concept, > but whenever anyone starts talking about them we get what seems like > overengineered examples that mak

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Alex Martelli
On Apr 1, 2006, at 10:52 AM, Tim Hochberg wrote: ... > overengineered examples that make my brain lock up. Someone who knows > something about adapters needs to go off and come up with the worlds > simplest, most light weight, dumb as a post, adapter proposal. It may Heh, funny -- that's basi

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Walter Dörwald
Alex Martelli wrote: > [...] > So, each entity which we can call a "registration of adaptation" (ROA for > short) is a tuple ( (T, P), A) where: > T is a type; > P is a unique string identifying a protocol; > A is a callable, such that, for any direct instance t of T > (i.e., one su

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Brett Cannon
Woohoo! I get it, finally! Some comments below, but I suddenly feel a little less stupid since I get the whole process now! =) On 4/1/06, Alex Martelli <[EMAIL PROTECTED]> wrote: > > On Apr 1, 2006, at 8:31 AM, Aahz wrote: > ... > > Seriously, I can almost see why you think adaptation is a

Re: [Python-3000] Iterating over a dict

2006-04-01 Thread Terry Reedy
"Thomas Lotze" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The reason I ask this on the python-3000 list is that I wonder whether > the > iterating behaviour of dicts might be changed in Python 3k, so that in > the > above code, foo() would be applied to the dict's values. Di

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Greg Ewing
Alex Martelli wrote: > The existence of dicts is > a laughably feeble excuse to avoid having adaptation in Python's > standard library, The point is whether it buys you anything important over using a dict. If you use it in such a wide-open way that it's just a mapping from anything to anythin

Re: [Python-3000] Iterating over a dict

2006-04-01 Thread Greg Ewing
Thomas Lotze wrote: > The reason I ask this on the python-3000 list is that I wonder whether the > iterating behaviour of dicts might be changed in Python 3k, I doubt it. This issue was considered very carefully when support for iteration was added to dicts, and I'm not aware that the reasons for

[Python-3000] It's a statement! It's a function! It's BOTH!

2006-04-01 Thread Talin
This is about the print / writeln debate. Let me say up front that I don't expect this posting in its original form to be widely accepted (In fact, I'll be disappointed if I don't get at least a sum total of -5000 on responses to this.) At the same time, however, I think that the issue that I am r

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Alex Martelli
On Apr 1, 2006, at 2:40 PM, Brett Cannon wrote: > Woohoo! I get it, finally! Some comments below, but I suddenly feel > a little less stupid since I get the whole process now! =) Well, I guess this may be the first time I've presented the thing properly, after all these many years -- in whi

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Brett Cannon
On 4/1/06, Alex Martelli <[EMAIL PROTECTED]> wrote: > > On Apr 1, 2006, at 2:40 PM, Brett Cannon wrote: > > > Woohoo! I get it, finally! Some comments below, but I suddenly feel > > a little less stupid since I get the whole process now! =) > > Well, I guess this may be the first time I've prese

Re: [Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]

2006-04-01 Thread Nick Coghlan
Greg Ewing wrote: > Alex Martelli wrote: > >> The existence of dicts is >> a laughably feeble excuse to avoid having adaptation in Python's >> standard library, > > The point is whether it buys you anything important > over using a dict. If you use it in such a wide-open > way that it's just a