classification
Title: 2to3 doesn't correct divisions
Type:
Components: 2to3 (2.x to 3.0 conversion tool) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: collinwinter, gpolo, rbp
Priority: Keywords:

Created on 2008-05-09 20:51 by gpolo, last changed 2008-05-10 13:15 by rbp.

Messages
msg66486 (view) Author: Guilherme Polo (gpolo) Date: 2008-05-09 20:51
Given the sample code:

  for i in range(len([1, 2]) / 2): pass

  print 2 / 3

2to3 tells no files need to be modified after running it over this code,
but range doesn't accept float values and the print result will differ.
Would it be too expensive for 2to3 to suggest changing '/' to '//' ?
msg66488 (view) Author: Collin Winter (collinwinter) Date: 2008-05-09 21:04
My gut feeling is that the number of cases where both operands are
written as literals is exceedingly small when compared to the number of
cases where one or both is an identifier. Since 2to3 doesn't support
type inference, we'd miss the relevant, interesting cases. However, if
you're interested in implementing a fix_literal_division fixer module
that would catch these cases, I'd be happy to advise on such a thing :)
msg66490 (view) Author: Guilherme Polo (gpolo) Date: 2008-05-09 21:26
If I were to add such fixer, should I wait for changes coming by gsoc
projects ? I did a quick pass through 2to3 code a while ago, but I'm
very far from understanding it in a good manner so I'm not sure if I
should starting doing that now because it looks like a GSoC project is
planning to change how 2to3 works.
msg66493 (view) Author: Collin Winter (collinwinter) Date: 2008-05-09 22:11
I say do it before the GSoC projects complete. Those projects will take
months, and we can't stop development for that long.
msg66517 (view) Author: Rodrigo Bernardo Pimentel (rbp) Date: 2008-05-10 13:15
+1 for going ahead and writing a fixer.
History
Date User Action Args
2008-05-10 13:15:53rbpsetnosy: + rbp
messages: + msg66517
2008-05-09 22:11:39collinwintersetmessages: + msg66493
2008-05-09 21:26:31gpolosetmessages: + msg66490
2008-05-09 21:04:55collinwintersetmessages: + msg66488
2008-05-09 20:51:50gpolocreate