Skip to content

Fix pyrefly type checker issues#235

Open
BurnySc2 wants to merge 15 commits intodevelopfrom
fix-pyrefly-errors
Open

Fix pyrefly type checker issues#235
BurnySc2 wants to merge 15 commits intodevelopfrom
fix-pyrefly-errors

Conversation

@BurnySc2
Copy link
Owner

@BurnySc2 BurnySc2 commented Jan 2, 2026

Fix #221

@BurnySc2 BurnySc2 changed the title Update pyrefly Fix pyrefly type checker issues Feb 18, 2026
@BurnySc2 BurnySc2 marked this pull request as ready for review February 18, 2026 14:28
assert result.observation.player_result

player_id_to_result = {}
player_id_to_result = dict[int, Result]()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this valid syntax?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix type checker issues

2 participants