[issue31417] Use the enumerate function where appropriate

2017-09-12 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> not a bug
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-12 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee: rhettinger -> 

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Vedran Čačić

Vedran Čačić added the comment:

Sorry, this seems like a classical example of "When all you have is a hammer, 
everything looks like a nail. Then, when you learn of a screwdriver, you 
suddenly see half of these nails as screws, completely ignoring there are other 
tools besides those two."

In fact, enumerate is _not_ the good choice in most of those cases, as the 
comments show. One should use zip, another should use ordinary iteration 
because the index isn't needed at all, and yet another should probably stay as 
it is, since that way it's more obvious that we're transforming each item in 
place. [When LHS is consts[i] and right is const, it's not easy to see they 
refer to the same place.]

Even the fourth I would argue is more readable in the current form, for a 
similar reason: when you base the decision on words[i], and the decision is to 
del words[i:], it's obvious you delete "it and everything after". Not so much 
in the "refactored" code.

Please don't do such things. One of Python's great strengths, especially in 
stdlib, is code stability. The only reason we're able to get anything done is 
that we have (or at least used to have) a great policy referred to in 
https://bugs.python.org/issue31417#msg301879, so we don't lose ourselves in 
enormous bikeshedding about how to best use the enormous expressivity of Python 
to write the code that works perfectly fine in some slightly different way.

--
nosy: +veky

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread R. David Murray

R. David Murray added the comment:

Mark: Yeah, I think my comment was directed more to haypo than you :)

--

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Mark Byrne

Mark Byrne added the comment:

Generally, we consider the danger of introducing bugs to be more significant 
than the benefit of the "cleanup" changes.  The fact that you are discussing 
further changes to the code in the PR make this more likely.

I haven't updated the PR with further code changes as suggested in the PR 
comments because the comments don't strictly relate to the changes put forward 
in this issue, and I don't want to go beyond the scope of the issue - the 
requested changes could go in a separate PR as needed.

The motivation is to use enumerate where it is a natural fit.
If you decide not to merge, then that is ok; let me know if I can help with 
anything.

--

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I concur with David in general. And as you can see there are questions to the 
concrete patch.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread R. David Murray

R. David Murray added the comment:

Anyone who uses stdlib code as examples of best practice doesn't understand the 
history of stdlib code.

Generally, we consider the danger of introducing bugs to be more significant 
than the benefit of the "cleanup" changes.  The fact that you are discussing 
further changes to the code in the PR make this more likely.

--

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread STINNER Victor

STINNER Victor added the comment:

> Thanks for wanting to improve Python, but we don't usually accept refactoring 
> requests like this.  We "fix" such issues when the code is touched for other 
> reasons.  We'll see what other developers think, though.

The standard library is used by some developers are the reference style for 
best practices. So it makes sense to "upgrade" to code to use enumarate(). I 
read the short change, enumerate() usage is appropriate.

--
nosy: +haypo

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread R. David Murray

R. David Murray added the comment:

Thanks for wanting to improve Python, but we don't usually accept refactoring 
requests like this.  We "fix" such issues when the code is touched for other 
reasons.  We'll see what other developers think, though.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> rhettinger
nosy: +rhettinger

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Roundup Robot

Changes by Roundup Robot :


--
keywords: +patch
pull_requests: +3490
stage:  -> patch review

___
Python tracker 

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



[issue31417] Use the enumerate function where appropriate

2017-09-11 Thread Mark Byrne

New submission from Mark Byrne:

To make code explicit and more readable

Use the enumerate function to replace occurrences of the pattern:

for i in range(len(sources)):
src = sources[i]

--
messages: 301871
nosy: Mark Byrne
priority: normal
severity: normal
status: open
title: Use the enumerate function where appropriate
type: behavior
versions: Python 3.7

___
Python tracker 

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