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: 2to3 doesn't correct divisions
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: aronacher, benjamin.peterson, collinwinter, gpolo, rbp, rhettinger
Priority: normal Keywords:

Created on 2008-05-09 20:51 by gpolo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg66486 - (view) Author: Guilherme Polo (gpolo) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) (Python committer) Date: 2008-05-10 13:15
+1 for going ahead and writing a fixer.
msg81629 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-02-11 04:53
I thought the right way to handle this is with a -3 option.  That's the
only way to reliably detect the intended meaning of / and its change in
meaning in 3.0.
msg81655 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-02-11 19:25
I concur with Raymond. There isn't yet a "-3" warning for class
division, though. I suppose the compiler could emit one when "/" is used
without from __future__ import division. That's another issue, though.
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47054
2009-02-11 19:25:46benjamin.petersonsetstatus: open -> closed
resolution: rejected
messages: + msg81655
2009-02-11 04:53:18rhettingersetnosy: + rhettinger
messages: + msg81629
2009-02-11 04:45:58ajaksu2setnosy: + benjamin.peterson
2008-12-08 15:04:48aronachersetnosy: + aronacher
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