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 and integer division
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alexander256, benjamin.peterson, mark.dickinson, rhettinger
Priority: normal Keywords:

Created on 2011-08-24 12:31 by alexander256, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg142879 - (view) Author: Alexander Rødseth (alexander256) Date: 2011-08-24 12:31
Hi,

2to3 is a great tool, but I think I found one case it doesn't catch, which is this change:

-        half = self.maxstars / 2
+        half = self.maxstars // 2

"/ 2" is an integer division, so it should be "// 3" in Python 3.

Thanks.
msg143001 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-08-26 06:53
> "/ 2" is an integer division, so it should be "// 3" in Python 3.

No, I don't think that's right: 2to3 has no way of knowing that the programmer intended an integer division here (self.maxstars could be a float).

Instead, you should always use '//' in Python 2 code where an integer division is intended.
msg143004 - (view) Author: Alexander Rødseth (alexander256) Date: 2011-08-26 10:20
Even though it's hard to cover every case, it should be possible in quite a few cases:

self.maxstars = 4
half = self.maxstars / 2
msg143006 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-08-26 10:57
Running python with the -3 command line option will warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57040
2019-07-30 08:56:30mark.dickinsonlinkissue37716 superseder
2011-08-26 10:57:29rhettingersetnosy: + rhettinger
messages: + msg143006
2011-08-26 10:20:29alexander256setmessages: + msg143004
2011-08-26 06:54:51mark.dickinsonsetstatus: open -> closed
nosy: + benjamin.peterson
resolution: not a bug
2011-08-26 06:53:17mark.dickinsonsetnosy: + mark.dickinson
messages: + msg143001
2011-08-24 12:31:03alexander256create