Conversation
| assert result.observation.player_result | ||
|
|
||
| player_id_to_result = {} | ||
| player_id_to_result = dict[int, Result]() |
There was a problem hiding this comment.
Yes, it seems to be since Python 3.10(?) and I learned this syntax only recently.
The only documentation about it I could find quickly is here:
https://peps.python.org/pep-0484/#instantiating-generic-classes-and-type-erasure
with the example
data = DefaultDict[int, bytes]()This also works for my_list = list[int]() and sets as well.
Speaking of py3.10+, I am not sure if this part of the code is being run in tests, so I'm not sure if this fails on python3.9.
Previously I had to change this to make it compatible with Python 3.9:
6fd85f7
Looking at the test runner, it seems it only complained about the union | operator, so this can actually stay the way it is, if I read this error right:
https://github.com/BurnySc2/python-sc2/actions/runs/22140288768/job/64002519619?pr=235
File "/root/python-sc2/sc2/main.py", line 586, in play_from_websocket
result = await _play_game(player, client, realtime, portconfig, game_time_limit=game_time_limit)
│ │ │ │ │ └ 240
│ │ │ │ └ None
│ │ │ └ False
│ │ └ <sc2.client.Client object at 0x7f7bba532490>
│ └ <sc2.player.Bot object at 0x7f7ba9d9f130>
└ <function _play_game at 0x7f7ba9de73a0>
File "/root/python-sc2/sc2/main.py", line 230, in _play_game
result = await _play_game_ai(client, player_id, player.ai, realtime, game_time_limit)
│ │ │ │ │ │ └ 240
│ │ │ │ │ └ False
│ │ │ │ └ <examples.terran.mass_reaper.MassReaperBot object at 0x7f7ba9d9f070>
│ │ │ └ <sc2.player.Bot object at 0x7f7ba9d9f130>
│ │ └ 1
│ └ <sc2.client.Client object at 0x7f7bba532490>
└ <function _play_game_ai at 0x7f7ba9de71f0>
File "/root/python-sc2/sc2/main.py", line 200, in _play_game_ai
await run_bot_iteration(iteration) # Main bot loop
│ └ 0
└ <function _play_game_ai.<locals>.run_bot_iteration at 0x7f7ba9e7d790>
> File "/root/python-sc2/sc2/main.py", line 160, in run_bot_iteration
await ai.on_step(iteration)
│ │ └ 0
│ └ <function MassReaperBot.on_step at 0x7f7ba9df3940>
└ <examples.terran.mass_reaper.MassReaperBot object at 0x7f7ba9d9f070>
File "/root/python-sc2/examples/terran/mass_reaper.py", line 154, in on_step
await self.my_distribute_workers()
│ └ <function MassReaperBot.my_distribute_workers at 0x7f7ba9df3af0>
└ <examples.terran.mass_reaper.MassReaperBot object at 0x7f7ba9d9f070>
File "/root/python-sc2/examples/terran/mass_reaper.py", line 313, in my_distribute_workers
deficit_townhalls = dict[int, dict[Literal["unit", "deficit"], Unit | int]]()
│ └ <class 'sc2.unit.Unit'>
└ typing.Literal
TypeError: unsupported operand type(s) for |: '_ProtocolMeta' and 'type'
Fix #221