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

2006-03-30 Thread Neal Norwitz
On 3/30/06, Terry Reedy <[EMAIL PROTECTED]> wrote: > > "Aahz" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > What do we want to tell people who have code like this: > > > > keys = d.keys() > > keys.sort() > > Could a good-enough code analyzer detect such, even if separated by > i

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

2006-03-30 Thread Terry Reedy
"Aahz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > What do we want to tell people who have code like this: > > keys = d.keys() > keys.sort() Could a good-enough code analyzer detect such, even if separated by intervening lines? If so, it could suggest sorted() as a fix. I wo

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

2006-03-30 Thread Ian Bicking
Alex Martelli wrote: > On Mar 30, 2006, at 5:53 PM, Greg Ewing wrote: > ... >>> Generally speaking I've remained suspicious of adaptation. >> I think to most people it seems like a solution >> looking for a problem. In all the code I've ever >> written, plain duck typing has been perfectly >> a

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

2006-03-30 Thread Guido van Rossum
> Adam DePrince wrote: > > No reason we can't make other string operations views as well ... > > concatenation is one example. If I recall, that's how snobol handles > > strings, view upon view upon view. But that's irrelevant for immutable strings -- views are about semantic links, not implement

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

2006-03-30 Thread Greg Ewing
Alex Martelli wrote: > If the framework consuming X requested adaptation-to-X on all objects > it's passed, This is the part that bothers me, I think. It seems like all these adaptation requests would be a huge burden on the framework developer. In PyGUI, for example, I currently have about 2 o

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

2006-03-30 Thread Alex Martelli
On Mar 30, 2006, at 5:53 PM, Greg Ewing wrote: ... >> Generally speaking I've remained suspicious of adaptation. > > I think to most people it seems like a solution > looking for a problem. In all the code I've ever > written, plain duck typing has been perfectly > adequate. I'm willing to con

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

2006-03-30 Thread Greg Ewing
Adam DePrince wrote: > Views > are not generated, they are either directly implemented, or returned. If you're thinking that the object would keep a set of pre-allocated views, there's a problem with that -- the views need to have a reference to the base object, thus creating a circular reference.

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

2006-03-30 Thread Greg Ewing
Adam DePrince wrote: > No reason we can't make other string operations views as well ... > concatenation is one example. If I recall, that's how snobol handles > strings, view upon view upon view. I don't think it was quite as bad as that. If I remember correctly, when you took a substring you d

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

2006-03-30 Thread Greg Ewing
Aahz wrote: > What do we want to tell people who have code like this: > > keys = d.keys() > keys.sort() I think the view returned in this case should be immutable, so that the above fails. Then we tell them to replace it with keys = sorted(d.keys()) In general, where we're changing the sema

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

2006-03-30 Thread Greg Ewing
Ian Bicking wrote: > Though if "Set([(1, None), (2, None)]) == > {1: None, 2: None}" is true, that's actually perfectly fine to me. That would be rather too loose for my tastes. A mapping can be *represented* as a set of tuples, but that's not the same thing as it *being* a set of tuples. > Gen

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

2006-03-30 Thread Guido van Rossum
On 3/30/06, Aahz <[EMAIL PROTECTED]> wrote: > What do we want to tell people who have code like this: > > keys = d.keys() > keys.sort() > > Not so much in terms of the fix, but where/why we drew the line about > what's supported by the value returned by d.keys() and what's not. I'm > not getting c

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

2006-03-30 Thread Greg Ewing
Guido van Rossum wrote: > But do we really want this? It's a pretty serious change in basic > semantics of collection data types, *and* it requires us to find a way > to determine unequivocally whether something is a set, sequence, > mapping, or multiset (and it can't be more than one!). If we *

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

2006-03-30 Thread Aahz
On Thu, Mar 30, 2006, Guido van Rossum wrote: > > Java does it this way and I think we can do the same thing: > > keys() and items() return views that behave like sets; values() > returns a view that behaves like a collection (aka multiset or bag). > Neither behaves like a list, which means that t

Re: [Python-3000] Parallel iteration syntax

2006-03-30 Thread Greg Ewing
Fabien Schwob wrote: > for x in iter1 and y in iter2: It would be tricky to avoid having that parsed as for x in (iter1 and y in iter2): since 'in' is also a valid part of an expression. That's one of ther reasons I suggested parens around the whole thing, which would make it unambiguous. T

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

2006-03-30 Thread Ian Bicking
Guido van Rossum wrote: >>A collection-specific protocol for testing equality would be reasonable. > > > I'm not sure what you mean here. Are you proposing using a different > method than __eq__()? No, that a collection that wanted to do a nice equality test might do something like: class Set:

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

2006-03-30 Thread Guido van Rossum
On 3/30/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Set-like is anything that subclasses baseset? No, it should to support duck typing. > But maybe there's a > deeper answer somewhere, as base* types seem a bit kludgy. Not just kludgy, but unpythonic. > A collection-specific protocol for testi

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

2006-03-30 Thread Ian Bicking
Guido van Rossum wrote: > On 3/30/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > >>Adam DePrince wrote: >> >>>There seemed to be a concensus in the community on the size of the view >>>proposal, and I'm reimplementing the PEP to reflect that. But what I >>>can't resolve is the other anciliary issu

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

2006-03-30 Thread Guido van Rossum
On 3/30/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Adam DePrince wrote: > > There seemed to be a concensus in the community on the size of the view > > proposal, and I'm reimplementing the PEP to reflect that. But what I > > can't resolve is the other anciliary issue: "To list or iter." I'm no

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

2006-03-30 Thread Nick Coghlan
Adam DePrince wrote: > There seemed to be a concensus in the community on the size of the view > proposal, and I'm reimplementing the PEP to reflect that. But what I > can't resolve is the other anciliary issue: "To list or iter." I'm not > yet ready to resolve that issue. The views don't resolv

Re: [Python-3000] Need list owner for py3k lists

2006-03-30 Thread Wolfgang Langner
Hello, On 3/30/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Barry made me the list owner for python-3000 and python-3000-checkins. > That's fine for a while, but long term I need to delegate this. Any > volunteers? (Especially during my trip to the UK I won't have time to > attend to the list

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

2006-03-30 Thread Adam DePrince
On Thu, 2006-03-30 at 12:05 +1200, Greg Ewing wrote: > Adam DePrince wrote: > > > SetView implements: > >.__contains__ > >.add > >.discard > >.__len__ > > But what would there be to inherit from the mixin? > Each view class will have entirely its own implementation > of these, d

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

2006-03-30 Thread Adam DePrince
On Thu, 2006-03-30 at 12:05 +1200, Greg Ewing wrote: > Stefan Rank wrote: > > >A big question is: Should slicing also return views? and why not? > > That's been considered before, in relation to strings. > The stumbling block is the problem of a view of a > small part of the object keeping th

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

2006-03-30 Thread Adam DePrince
On Thu, 2006-03-30 at 20:23 +1000, Nick Coghlan wrote: > Robert Brewer wrote: > > Nick Coghlan wrote: > >> There are three big use cases: > >> > >>dict.keys > >>dict.values > >>dict.items > >> > >> Currently these all return lists, which may be expensive in > >> terms of copying. They

Re: [Python-3000] Need list owner for py3k lists

2006-03-30 Thread Guido van Rossum
I've got two volunteers. Thanks! On 3/30/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Barry made me the list owner for python-3000 and python-3000-checkins. > That's fine for a while, but long term I need to delegate this. Any > volunteers? (Especially during my trip to the UK I won't have ti

Re: [Python-3000] Need list owner for py3k lists

2006-03-30 Thread skip
Guido> Barry made me the list owner for python-3000 and Guido> python-3000-checkins. That's fine for a while, but long term I Guido> need to delegate this. Any volunteers? Feel free to add me. I moderate a number of lists and have a little script that helps me plow through moderatio

Re: [Python-3000] Need list owner for py3k lists

2006-03-30 Thread Fred L. Drake, Jr.
On Thursday 30 March 2006 12:32, Guido van Rossum wrote: > Barry made me the list owner for python-3000 and python-3000-checkins. > That's fine for a while, but long term I need to delegate this. Any > volunteers? (Especially during my trip to the UK I won't have time to > attend to the list ow

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

2006-03-30 Thread Adam DePrince
On Wed, 2006-03-29 at 11:08 -0800, Brett Cannon wrote: > On 3/29/06, Adam DePrince <[EMAIL PROTECTED]> wrote: > > > > > set interface where we could have a __container__/__view__/__set__ > > > > Why would I call a method to get a view on an object when the object can > > just as well implement the

[Python-3000] Need list owner for py3k lists

2006-03-30 Thread Guido van Rossum
Barry made me the list owner for python-3000 and python-3000-checkins. That's fine for a while, but long term I need to delegate this. Any volunteers? (Especially during my trip to the UK I won't have time to attend to the list owner responsibilities.) There's really not much to do, except maybe a

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

2006-03-30 Thread Adam DePrince
[sni[] > All I think we're currently missing is an idea of 'what magic methods does an > object need to provide in order to pretend to be a container, rather than > just > an iterable?' > > Change dict.keys/values/items to return views which implement that set of > methods, and all should be g

Re: [Python-3000] Parallel iteration syntax

2006-03-30 Thread Guido van Rossum
Save your breath on this one, folks. This isn't going to happen. -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http:/

Re: [Python-3000] Parallel iteration syntax

2006-03-30 Thread Giovanni Bajo
Greg Ewing <[EMAIL PROTECTED]> wrote: >> for i,(x,y) in enumerate(izip(iter1, iter2)): >> ... >> >> must be translated to: >> >> for (i,x in enumerate(iter1), y in iter2): > > Maybe the functionality of enumerate() could be > incorporated into the syntax as well. > >for (i in *, x in i

Re: [Python-3000] Parallel iteration syntax

2006-03-30 Thread Fabien Schwob
> > And what about the ambiguity in parsing: > > > > for (x in iter1,y,z in iter2): > > ... > > It would probably be necessary to require some > parens there, e.g. > >for (x in iter1, (y,z) in iter2): > ... I've also a proposition, but I don't know if it can't be done since I don't

Re: [Python-3000] [Python-Dev] Class decorators

2006-03-30 Thread Ben . Young
[EMAIL PROTECTED] wrote on 30/03/2006 13:01:25: > [EMAIL PROTECTED] wrote: > > [EMAIL PROTECTED] wrote on > > 30/03/2006 11:38:30: > > > >> Jack Diederich wrote: > >> > >> > Classes have a unique property in that they are the easiest way to > > make > >> > little namespaces in python. > >> >

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

2006-03-30 Thread Kevin Jacobs <[EMAIL PROTECTED]>
On 3/29/06, Ian Bicking <[EMAIL PROTECTED]> wrote: Greg Ewing wrote:> On 3/29/06, Adam DePrince <[EMAIL PROTECTED]> wrote:>> rs.execute( "select upc, description, price from my_table" ) > data = "" 'price','upc')> print type( data )>> >> Seems to me it would be a better idea for the DB>

Re: [Python-3000] Parallel iteration syntax

2006-03-30 Thread Greg Ewing
Giovanni Bajo wrote: > And what about the ambiguity in parsing: > > for (x in iter1,y,z in iter2): > ... It would probably be necessary to require some parens there, e.g. for (x in iter1, (y,z) in iter2): ... -- Greg ___ Python-3000 mail

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

2006-03-30 Thread Nick Coghlan
Robert Brewer wrote: > Nick Coghlan wrote: >> There are three big use cases: >> >>dict.keys >>dict.values >>dict.items >> >> Currently these all return lists, which may be expensive in >> terms of copying. They all have iter* variants which while >> memory efficient, are far less conve

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

2006-03-30 Thread Nick Coghlan
Greg Ewing wrote: > Brett Cannon wrote: >> Without a direct reason in terms of the language needing a >> standardization of an interface, perhaps we just don't need > > views. > > On the contrary, views are a very useful idea, *as a > design pattern*. What we *don't* need in Python, as far > as I

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

2006-03-30 Thread Nick Coghlan
Adam DePrince wrote: > On Wed, 2006-03-29 at 21:15 +1000, Nick Coghlan wrote: >> Paul Moore wrote: >>> On 3/29/06, Brett Cannon <[EMAIL PROTECTED]> wrote: Without a direct reason in terms of the language needing a standardization of an interface, perhaps we just don't need views. If