Search code examples
numpypygameopenai-gym

Python - TypeError: unsupported operand type(s) for +: 'zip' and 'int'


I am modifying some Python 2.7 code to be compatible with Python 3.7. I made as many edits as I could, until this happens:

C:\Users\AyazA\Desktop\schema-games>python schema_games/breakout/play.py StandardBreakout
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
[34m--------------------------------------------------------------------------------[0m
[34mStarting interactive game. Press <ESC> at any moment to terminate.[0m
[34m--------------------------------------------------------------------------------[0m
Traceback (most recent call last):
  File "schema_games/breakout/play.py", line 93, in <module>
    play_game(getattr(games, variant), debug=debug, cheat_mode=cheat_mode)
  File "schema_games/breakout/play.py", line 54, in play_game
    play(env, fps=fps, keys_to_action=keys_to_action, zoom=ZOOM_FACTOR)
  File "C:\Python37\lib\site-packages\gym\utils\play.py", line 79, in play
    env.reset()
  File "C:\Users\AyazA\Desktop\schema-games\schema_games\breakout\core.py", line 301, in reset
    self.layout_sanity_check()
  File "C:\Users\AyazA\Desktop\schema-games\schema_games\breakout\core.py", line 473, in layout_sanity_check
    all_occupied_nzis = [nzi for obj in considered_objects
  File "C:\Users\AyazA\Desktop\schema-games\schema_games\breakout\core.py", line 474, in <listcomp>
    for nzi in obj.offset_nzis if obj.visible]
  File "C:\Users\AyazA\Desktop\schema-games\schema_games\breakout\objects.py", line 190, in offset_nzis
    offset_nzis_from_position(self._nzis, self._position)
  File "C:\Users\AyazA\Desktop\schema-games\schema_games\breakout\utils.py", line 57, in offset_nzis_from_position
    return zip(*(np.add(nzis, np.array(pos))).T)
TypeError: unsupported operand type(s) for +: 'zip' and 'int'

I tried unzipping the contents of the zipped tuple, but it was of no use. I tried even further to look into forcing the two to add (both pos and nzis are of type ndarray), only to not work. Is this another Python 2.7 incompatibility that I am missing? Here is the source code and the corresponding repository that I forked from


Solution

  • False alarm. It was a collection of problems in the file itself. There were many instances of the zip function that needed to be replaced with list(zip) instead.