This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: make the fix_dict fixer smarter
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: benjamin.peterson, collinwinter, eric.araujo, georg.brandl, rbp, rhettinger
Priority: normal Keywords: patch

Created on 2008-07-19 13:51 by benjamin.peterson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
smarter_fix_dict.diff benjamin.peterson, 2008-07-19 19:17
Messages (12)
msg70031 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-19 13:51
Can we make the part of fix_dict that converts d.items/values/keys to
list(d.items) explicit? Most of the time, it's fine if the method
returns a view and can be a bit of a performance hit to convert it to a
list.
msg70035 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-19 14:03
Rather, the list of special contexts in which it is ok to not use list()
should be extended.
msg70036 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-19 14:08
Exactly! For example, if the .items call is in a for loop, list()
doesn't need to be called.
msg70051 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-19 19:17
Here's a patch that doesn't add the enclosing list call in a for loop.
msg70052 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-07-19 19:58
for k in d.keys():
   return k   # needs to return a list
msg70095 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-20 22:38
>for k in d.keys():
>   return k   # needs to return a list

Could you explain this a bit more?
msg70097 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-07-21 02:44
The example was mucked-up :(  The question is that when for-looping 
over d.keys/items etc, how you know that the body of the loop isn't 
going to mutate the dict?
msg70134 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008-07-22 04:04
I think the proper way to address this is via the confidence levels that
Rodrigo Bernardo Pimentel is adding for his Summer of Code project. The
idea is that you'll be able to say "let me inspect any changes where the
fixer is less than X% confident". fix_dict and for loops would be one
such place.

Until that mechanism is in place, I agree with Raymond that we should
err on the side of correctness.
msg70145 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-22 12:32
Ok. I'll mark this as something to do for 2.7/3.1.
msg72602 - (view) Author: Rodrigo Bernardo Pimentel (rbp) (Python committer) Date: 2008-09-05 15:50
I haven't managed to successfully complete the summer of code, due to
some personal problems, but I'm still working on 2to3 and on confidence
ranking for it.

There's a bzr branch with its current implementation at
http://isnomore.net/bzr/2to3 . I did an initial implementation of
confidence penalties on fix_dict for special contexts.

I'm still working on it (and on confidence ranking in general), but
please take a look and let me know what you think.
msg72739 - (view) Author: Rodrigo Bernardo Pimentel (rbp) (Python committer) Date: 2008-09-07 15:03
(I've just realized it's not working properly for fix_dict; I'm fixing
it and will drop a note here when it is)
msg114603 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-21 23:11
Is this still relevant?
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47667
2010-08-21 23:32:53benjamin.petersonsetstatus: open -> closed
2010-08-21 23:14:32benjamin.petersonsetresolution: wont fix
2010-08-21 23:13:43eric.araujosetnosy: + eric.araujo
2010-08-21 23:11:07georg.brandlsetmessages: + msg114603
2008-09-07 15:03:10rbpsetmessages: + msg72739
2008-09-05 15:50:46rbpsetmessages: + msg72602
2008-07-22 12:32:28benjamin.petersonsetmessages: + msg70145
versions: + Python 3.1, Python 2.7
2008-07-22 04:04:38collinwintersetnosy: + rbp
messages: + msg70134
2008-07-21 02:44:14rhettingersetmessages: + msg70097
2008-07-20 22:38:40benjamin.petersonsetmessages: + msg70095
2008-07-19 19:58:58rhettingersetnosy: + rhettinger
messages: + msg70052
2008-07-19 19:17:07benjamin.petersonsetfiles: + smarter_fix_dict.diff
keywords: + patch
messages: + msg70051
2008-07-19 14:08:16benjamin.petersonsetmessages: + msg70036
title: make the fix_dict fixer explicit -> make the fix_dict fixer smarter
2008-07-19 14:03:24georg.brandlsetnosy: + georg.brandl
messages: + msg70035
2008-07-19 13:51:59benjamin.petersoncreate