Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2to3 and integer division #57040

Closed
alexander256 mannequin opened this issue Aug 24, 2011 · 4 comments
Closed

2to3 and integer division #57040

alexander256 mannequin opened this issue Aug 24, 2011 · 4 comments
Labels
topic-2to3 type-bug An unexpected behavior, bug, or error

Comments

@alexander256
Copy link
Mannequin

alexander256 mannequin commented Aug 24, 2011

BPO 12831
Nosy @rhettinger, @mdickinson, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-08-26.06:54:51.536>
created_at = <Date 2011-08-24.12:31:03.663>
labels = ['invalid', 'type-bug', 'expert-2to3']
title = '2to3 and integer division'
updated_at = <Date 2011-08-26.10:57:29.516>
user = 'https://bugs.python.org/alexander256'

bugs.python.org fields:

activity = <Date 2011-08-26.10:57:29.516>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2011-08-26.06:54:51.536>
closer = 'mark.dickinson'
components = ['2to3 (2.x to 3.x conversion tool)']
creation = <Date 2011-08-24.12:31:03.663>
creator = 'alexander256'
dependencies = []
files = []
hgrepos = []
issue_num = 12831
keywords = []
message_count = 4.0
messages = ['142879', '143001', '143004', '143006']
nosy_count = 4.0
nosy_names = ['rhettinger', 'mark.dickinson', 'benjamin.peterson', 'alexander256']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue12831'
versions = ['Python 3.2']

@alexander256
Copy link
Mannequin Author

alexander256 mannequin commented Aug 24, 2011

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.

@alexander256 alexander256 mannequin added topic-2to3 type-bug An unexpected behavior, bug, or error labels Aug 24, 2011
@mdickinson
Copy link
Member

"/ 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.

@alexander256
Copy link
Mannequin Author

alexander256 mannequin commented Aug 26, 2011

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

@rhettinger
Copy link
Contributor

Running python with the -3 command line option will warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-2to3 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants