[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-10 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Please pass the word along if you get a chance :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-09 Thread Daniel Stutzbach

Daniel Stutzbach  added the comment:

> Daniel, we need to sync-up on the meaning of marking a report as 
> "accepted".  Traditionally it denotes an approved patch, not a agreement > 
> that the bug is valid.

Woops!  Thanks for the correction.  For what it's worth, a quick search of 
issues with Resolution: accepted and Stage: needs patch suggests that Éric 
Araujo has perhaps been using the same misinterpretation as I have.  I'm not 
sure if I got the behavior from him, if he got it from me, or if we both 
arrived there independently. ;-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-09 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-09 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Max, thanks for reporting this.  I've replaced the sample code, making it work 
correctly and more clearly showing the logic.

See r85345 and r85346.

Daniel, we need to sync-up on the meaning of marking a report as "accepted".  
Traditionally it denotes an approved patch, not a agreement that the bug is 
valid.

--
resolution: accepted -> fixed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: [issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-09 Thread Senthil Kumaran
On Fri, Oct 08, 2010 at 06:25:26PM +, Alexander Belopolsky wrote:
> In this case, I wonder if "equivalent to" code should be added to the
> section for enumerate() and map().  Also since any() and all() have
> "equivalent to" code, I think min(), max() and sum() deserve it as
> well.

I think, you are asking for consistency in docs, right?

As a sidenote those explanations should be okay, but merging it with
the explanation of the functions may add to confusion (like the zip
example did in this case). 

Even I am +1 on removing that complex equivalent code in the zip
documentation, as it can confusing to the newcomer. But I am also okay
with moving that 'equivalent to code' further down in the
explanation.
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-08 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Refuse the temptation to hypergeneralize ;-)

Also refuse the temptation to double the size of the docs (more != better).

In the case of min/max, the pure python versions may add some value in showing 
that the first match is what is returned.  But the code will also be a bit 
convoluted because it needs paths for key-argument case and for the screwy 
interpretation of 1 arg vs multiple args.

The pure python code is there for any() and all() to show the early out feature 
and to suggest how you could roll-your-own if you want different behavior (such 
as returning the value of the first exception).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-08 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

On Thu, Oct 7, 2010 at 3:37 PM, Raymond Hettinger
 wrote:
..
> I'll update the docs with an equivalent that works and that has a comment 
> showing when the
> StopIteration is raised and caught.
>

In this case, I wonder if "equivalent to" code should be added to the
section for enumerate() and map().  Also since any() and all() have
"equivalent to" code, I think min(), max() and sum() deserve it as
well.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-07 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

I'll update the docs with an equivalent that works and that has a comment 
showing when the StopIteration is raised and caught.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-07 Thread Max

Max  added the comment:

Personally, I find it impossible in some cases to understand exactly what a 
function does just from reading a textual description. In those cases, I always 
refer to the equivalent code if it's given. In fact that's the reason I was 
looking going the zip equivalent function!

I would feel it's a loss if equivalent code disappear from the docs.

I understand sometimes the code requires maintenance, but I'd rather live with 
some temporary bugs than lose the equivalent code.

As to subtleties of how it works, that's not really a concern, if that's the 
only way to understand the precise meaning of whatever it explains.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-07 Thread Daniel Stutzbach

Daniel Stutzbach  added the comment:

> I suggest removing the "equivalent to" code from the zip section and
> replacing it with an example showing how to use zip with a for loop
> similar to the example illustrating enumerate.

+1

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-07 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

As Daniel pointed out, the "equivalent to" code in builtins section comes from 
2.x itertools documentation where and equivalent generator definition is 
presented for each function.  While these definitions are helpful when used for 
documenting a module oriented towards more advanced users, I doubt that 
exposing novices who are looking up builtins to the yield keyword and 
generators is a good idea.  The zip() example is particularly problematic.  
Conceptually, zip is a very simple function, but the "equivalent to" code is 
not easy to decipher.   The reliance on StopIteration exception escaping from 
map to break out of the infinite loop is clever, but not obvious.  Moreover, as 
this bug demonstrates, this trick relies on subtle details that changed in 3.x.

I suggest removing the "equivalent to" code from the zip section and replacing 
it with an example showing how to use zip with a for loop similar to the 
example illustrating enumerate.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-06 Thread Douglas Leeder

Changes by Douglas Leeder :


--
nosy: +Douglas.Leeder

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-05 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
nosy:  -loewis

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-05 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

Note that the following variant where maps are replaced with list 
comprehensions seems to work:

def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By   

   
iterables = [iter(i) for i in iterables]
while iterables:
yield tuple([next(j) for j in iterables])

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10029] "Equivalent to" code for zip is wrong in Python 3

2010-10-05 Thread Daniel Stutzbach

Daniel Stutzbach  added the comment:

The code was taken from the itertools.izip documentation for Python 2, where it 
did work.

In Python 2, next() raises StopIteration which is propagated up and causes the 
izip() to stop.  In Python 3, map is itself a generator and the StopIteration 
terminates the map operation instead of terminating the zip operation.

--
nosy: +stutzbach
resolution:  -> accepted
stage:  -> needs patch
title: bug in sample code in documentation -> "Equivalent to" code for zip is 
wrong in Python 3
versions: +Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com