Skip to content

Commit

Permalink
Re-add union type to fix python3.9 and 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnySc2 committed Dec 17, 2024
1 parent c3ede8f commit 075f72d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/terran/onebase_battlecruiser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations


from sc2 import maps
from sc2.bot_ai import BotAI
from sc2.data import Difficulty, Race
Expand Down
9 changes: 5 additions & 4 deletions generate_dicts_from_data_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def main():
from sc2.ids.upgrade_id import UpgradeId
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId
from typing import Union
"""

dict_file_paths = [
Expand All @@ -515,23 +517,22 @@ def main():
init_file_path = dicts_path / "__init__.py"
init_header = f"""# DO NOT EDIT!
# This file was automatically generated by "{file_name}"
"""
"""
generate_init_file(dict_file_paths=dict_file_paths, file_path=init_file_path, file_header=init_header)

dump_dict_to_file(
unit_train_abilities,
unit_creation_dict_path,
dict_name="TRAIN_INFO",
file_header=file_header,
dict_type_annotation=": dict[UnitTypeId, dict[UnitTypeId, dict[str, AbilityId | bool | UnitTypeId]]]",
dict_type_annotation=": dict[UnitTypeId, dict[UnitTypeId, dict[str, Union[AbilityId, bool, UnitTypeId]]]]",
)
dump_dict_to_file(
unit_research_abilities,
unit_research_abilities_dict_path,
dict_name="RESEARCH_INFO",
file_header=file_header,
dict_type_annotation=": dict[UnitTypeId, dict[UpgradeId, dict[str, AbilityId | bool | UnitTypeId | UpgradeId]]]",
dict_type_annotation=": dict[UnitTypeId, dict[UpgradeId, dict[str, Union[AbilityId, bool, UnitTypeId, UpgradeId]]]]",
)
dump_dict_to_file(
unit_trained_from,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ ignore = [
"N802", # Function name `...` should be lowercase
"N806", # Variable `...` in function should be lowercase.
"SIM102", # Use a single `if` statement instead of nested `if` statements
"UP007", # Use `X | Y` for type annotations
]

[tool.ruff.pyupgrade]
Expand Down
1 change: 0 additions & 1 deletion sc2/dicts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# DO NOT EDIT!
# This file was automatically generated by "generate_dicts_from_data_json.py"


__all__ = [
"generic_redirect_abilities",
"unit_abilities",
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/generic_redirect_abilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


GENERIC_REDIRECT_ABILITIES: dict[AbilityId, AbilityId] = {
AbilityId.ARMORYRESEARCH_TERRANSHIPWEAPONSLEVEL1: AbilityId.RESEARCH_TERRANSHIPWEAPONS,
AbilityId.ARMORYRESEARCH_TERRANSHIPWEAPONSLEVEL2: AbilityId.RESEARCH_TERRANSHIPWEAPONS,
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/unit_abilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


UNIT_ABILITIES: dict[UnitTypeId, set[AbilityId]] = {
UnitTypeId.ADEPT: {
AbilityId.ADEPTPHASESHIFT_ADEPTPHASESHIFT,
Expand Down
4 changes: 3 additions & 1 deletion sc2/dicts/unit_research_abilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId

RESEARCH_INFO: dict[UnitTypeId, dict[UpgradeId, dict[str, AbilityId | bool | UnitTypeId | UpgradeId]]] = {
from typing import Union

RESEARCH_INFO: dict[UnitTypeId, dict[UpgradeId, dict[str, Union[AbilityId, bool, UnitTypeId, UpgradeId]]]] = {
UnitTypeId.ARMORY: {
UpgradeId.TERRANSHIPWEAPONSLEVEL1: {"ability": AbilityId.ARMORYRESEARCH_TERRANSHIPWEAPONSLEVEL1},
UpgradeId.TERRANSHIPWEAPONSLEVEL2: {
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/unit_tech_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


UNIT_TECH_ALIAS: dict[UnitTypeId, set[UnitTypeId]] = {
UnitTypeId.BARRACKSFLYING: {UnitTypeId.BARRACKS},
UnitTypeId.BARRACKSREACTOR: {UnitTypeId.REACTOR},
Expand Down
4 changes: 3 additions & 1 deletion sc2/dicts/unit_train_build_abilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId

TRAIN_INFO: dict[UnitTypeId, dict[UnitTypeId, dict[str, AbilityId | bool | UnitTypeId]]] = {
from typing import Union

TRAIN_INFO: dict[UnitTypeId, dict[UnitTypeId, dict[str, Union[AbilityId, bool, UnitTypeId]]]] = {
UnitTypeId.BARRACKS: {
UnitTypeId.GHOST: {
"ability": AbilityId.BARRACKSTRAIN_GHOST,
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/unit_trained_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


UNIT_TRAINED_FROM: dict[UnitTypeId, set[UnitTypeId]] = {
UnitTypeId.ADEPT: {UnitTypeId.GATEWAY, UnitTypeId.WARPGATE},
UnitTypeId.ARMORY: {UnitTypeId.SCV},
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/unit_unit_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


UNIT_UNIT_ALIAS: dict[UnitTypeId, UnitTypeId] = {
UnitTypeId.ADEPTPHASESHIFT: UnitTypeId.ADEPT,
UnitTypeId.BANELINGBURROWED: UnitTypeId.BANELING,
Expand Down
1 change: 1 addition & 0 deletions sc2/dicts/upgrade_researched_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# from sc2.ids.buff_id import BuffId
# from sc2.ids.effect_id import EffectId


UPGRADE_RESEARCHED_FROM: dict[UpgradeId, UnitTypeId] = {
UpgradeId.ADEPTPIERCINGATTACK: UnitTypeId.TWILIGHTCOUNCIL,
UpgradeId.ANABOLICSYNTHESIS: UnitTypeId.ULTRALISKCAVERN,
Expand Down

0 comments on commit 075f72d

Please sign in to comment.