Skip to content

Commit 88c2c8c

Browse files
committed
Changes from strict type checking
1 parent 5872ae3 commit 88c2c8c

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

rlbot/config.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import tomllib
22
from pathlib import Path
3-
from typing import Any
3+
from typing import Any, Literal
44

55
import rlbot.flat as flat
66
from rlbot.utils.logging import DEFAULT_LOGGER as logger
@@ -11,7 +11,7 @@ class ConfigParsingException(Exception):
1111
pass
1212

1313

14-
def __enum(table: dict, key: str, enum: Any, default: int = 0) -> Any:
14+
def __enum(table: dict[str, str | Any], key: str, enum: Any, default: int = 0) -> Any:
1515
if key not in table:
1616
return enum(default)
1717
try:
@@ -24,35 +24,35 @@ def __enum(table: dict, key: str, enum: Any, default: int = 0) -> Any:
2424
)
2525

2626

27-
def __str(table: dict, key: str, default: str = "") -> str:
27+
def __str(table: dict[str, str | Any], key: str, default: str = "") -> str:
2828
v = table.get(key, default)
2929
if isinstance(v, str):
3030
return v
3131
raise ConfigParsingException(f"'{key}' has value {repr(v)}. Expected a string.")
3232

3333

34-
def __bool(table: dict, key: str, default: bool = False) -> bool:
34+
def __bool(table: dict[str, bool | Any], key: str, default: bool = False) -> bool:
3535
v = table.get(key, default)
3636
if isinstance(v, bool):
3737
return v
3838
raise ConfigParsingException(f"'{key}' has value {repr(v)}. Expected a bool.")
3939

4040

41-
def __int(table: dict, key: str, default: int = 0) -> int:
41+
def __int(table: dict[str, int | Any], key: str, default: int = 0) -> int:
4242
v = table.get(key, default)
4343
if isinstance(v, int):
4444
return v
4545
raise ConfigParsingException(f"'{key}' has value {repr(v)}. Expected an int.")
4646

4747

48-
def __table(table: dict, key: str) -> dict:
48+
def __table(table: dict[str, dict[str, Any] | Any], key: str) -> dict[str, Any]:
4949
v = table.get(key, dict())
5050
if isinstance(v, dict):
51-
return v
51+
return v # type: ignore
5252
raise ConfigParsingException(f"'{key}' has value {repr(v)}. Expected a table.")
5353

5454

55-
def __team(table: dict) -> int:
55+
def __team(table: dict[str, Literal["blue", "orange", 0, 1] | Any]) -> int:
5656
if "team" not in table:
5757
return 0
5858
v = table["team"]
@@ -81,7 +81,7 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
8181
match_table = __table(config, "match")
8282
mutator_table = __table(config, "mutators")
8383

84-
players = []
84+
players: list[flat.PlayerConfiguration] = []
8585
for car_table in config.get("cars", []):
8686
car_config = __str(car_table, "config_file")
8787
name = __str(car_table, "name")
@@ -101,20 +101,24 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
101101
variety, use_config = flat.Human(), False
102102
case "partymember":
103103
logger.warning("PartyMember player type is not supported yet.")
104-
variety, use_config = flat.PartyMember, False
104+
variety, use_config = flat.PartyMember(), False
105105
case t:
106106
raise ConfigParsingException(
107107
f"Invalid player type {repr(t)} for player {len(players)}."
108108
)
109109

110110
if use_config and car_config:
111111
abs_config_path = (config_path.parent / car_config).resolve()
112-
players.append(load_player_config(abs_config_path, variety, team, name, loadout_file)) # type: ignore
112+
players.append(
113+
load_player_config(abs_config_path, variety, team, name, loadout_file) # type: ignore
114+
)
113115
else:
114116
loadout = load_player_loadout(loadout_file, team) if loadout_file else None
115-
players.append(flat.PlayerConfiguration(variety, name, team, loadout=loadout)) # type: ignore
117+
players.append(
118+
flat.PlayerConfiguration(variety, name, team, loadout=loadout)
119+
)
116120

117-
scripts = []
121+
scripts: list[flat.ScriptConfiguration] = []
118122
for script_table in config.get("scripts", []):
119123
if script_config := __str(script_table, "config_file"):
120124
abs_config_path = (config_path.parent / script_config).resolve()

rlbot/managers/bot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def _run(self):
173173
if self._latest_packet is not None:
174174
self._packet_processor(self._latest_packet)
175175
self._latest_packet = None
176+
case _:
177+
pass
176178

177179
def run(
178180
self,

rlbot/managers/hivemind.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def _run(self):
185185
if self._latest_packet is not None:
186186
self._packet_processor(self._latest_packet)
187187
self._latest_packet = None
188+
case _:
189+
pass
188190

189191
def run(
190192
self,

rlbot/managers/script.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def _run(self):
142142
if self._latest_packet is not None:
143143
self._packet_processor(self._latest_packet)
144144
self._latest_packet = None
145+
case _:
146+
pass
145147

146148
def run(
147149
self,

rlbot/utils/gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def find_open_server_port() -> int:
5050

5151
def launch(
5252
main_executable_path: Path, main_executable_name: str
53-
) -> tuple[subprocess.Popen, int]:
53+
) -> tuple[subprocess.Popen[bytes], int]:
5454
directory, path = find_main_executable_path(
5555
main_executable_path, main_executable_name
5656
)

0 commit comments

Comments
 (0)