deuces icon indicating copy to clipboard operation
deuces copied to clipboard

TypeError after 2to3

Open nittanycolonial opened this issue 9 years ago • 5 comments

I have used 2to3 to run this library and I keep on running into a TypeError of:

TypeError: unsupported operand type(s) for >>: 'float' and 'int'

def get_lexographically_next_bit_sequence(self, bits): t = (bits | (bits - 1)) + 1 next = t | ((((t & -t) // (bits & -bits)) >> 1) - 1) yield next while True: t = (next | (next - 1)) + 1 next = t | ((((t & -t) // (next & -next)) >> 1) - 1) yield next

I have tried other parts of the library and they work, so I'm pretty confident that 2to3 worked fine. It's only when I load the evaluator that this message pops up. Any thoughts?

nittanycolonial avatar Apr 19 '17 03:04 nittanycolonial

I have the same issue while running go.py.

furuutsuponchisamurai avatar May 20 '17 20:05 furuutsuponchisamurai

/ means float division in Python 3. If you want integer division, use /. Unfortunately, 2to3 isn't smart enough to take care of this for you.

There's a PR here that takes care of Py3 compatibility: #21 (apparently duplicated by #23).

mpenkov avatar Aug 20 '17 13:08 mpenkov

@mpenkov thanks but did your answer not format properly? I guess I'm not seeing a difference in the slashes as you mention them. I have tried using both / and // in my code and it will still not work.

nittanycolonial avatar Aug 27 '17 17:08 nittanycolonial

@nittanycolonial Whoops. Here's what I meant:

If you want integer division, use //

Have a look at the pull-requests I mentioned for more info.

mpenkov avatar Aug 28 '17 02:08 mpenkov

Hello guys, I did a pull to the original project and I couldn't seem to get it working straight away on python3.5. I've forked the project and it now works with python3.5.

The main things were: 1.) Python 2 does floor division with the / operator, Python 3 introduced // for floor division. 2.) For some reason after having done 2to3 conversion, I was getting a byte object in the section of the code and had to change it to string for it to work.

hope this helps.

luchaoo7 avatar Aug 31 '18 14:08 luchaoo7