Skip to content

Commit 6bd4f4f

Browse files
Added a script for for strict type checking (not required for CI). Updated the code to pass this script.
1 parent 349bbbe commit 6bd4f4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+204
-193
lines changed

.mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mypy]
2+
3+
exclude = _test\.py$
4+
5+
strict = false
6+
disable_error_code = type-arg

pacai/agents/greedy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import typing
2+
13
import pacai.core.action
24
import pacai.core.agent
35
import pacai.core.gamestate
@@ -42,7 +44,7 @@ class GreedyFeatureAgent(GreedyAgent):
4244
def __init__(self,
4345
feature_extractor_func: pacai.core.features.FeatureExtractor | pacai.util.reflection.Reference | str =
4446
pacai.core.features.score_feature_extractor,
45-
**kwargs) -> None:
47+
**kwargs: typing.Any) -> None:
4648
super().__init__(**kwargs)
4749

4850
self.weights: pacai.core.features.WeightDict = pacai.core.features.WeightDict()
@@ -55,7 +57,7 @@ def __init__(self,
5557
def evaluate_state(self,
5658
state: pacai.core.gamestate.GameState,
5759
action: pacai.core.action.Action | None = None,
58-
**kwargs) -> float:
60+
**kwargs: typing.Any) -> float:
5961
if (action is None):
6062
action = pacai.core.action.STOP
6163

pacai/agents/mdp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self,
2222
discount_rate: float = DEFAULT_DISCOUNT_RATE,
2323
exploration_rate: float = DEFAULT_EXPLORATION_RATE,
2424
mdp_state_class: typing.Type | pacai.util.reflection.Reference | str | None = pacai.core.mdp.MDPStateBoard,
25-
**kwargs) -> None:
25+
**kwargs: typing.Any) -> None:
2626
super().__init__(**kwargs)
2727

2828
if (mdp_state_class is None):

pacai/agents/minimax.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import math
3+
import typing
34

45
import pacai.core.action
56
import pacai.core.agent
@@ -21,7 +22,7 @@ def __init__(self,
2122
ply_count: int = DEFAULT_PLY_COUNT,
2223
alphabeta_prune: bool = False,
2324
expectimax: bool = False,
24-
**kwargs) -> None:
25+
**kwargs: typing.Any) -> None:
2526
super().__init__(**kwargs)
2627

2728
# Parse (possibly string) arguments.
@@ -55,7 +56,7 @@ def __init__(self,
5556
def evaluate_state(self,
5657
state: pacai.core.gamestate.GameState,
5758
action: pacai.core.action.Action | None = None,
58-
**kwargs) -> float:
59+
**kwargs: typing.Any) -> float:
5960
self._stats_states_evaluated[-1] += 1
6061
return super().evaluate_state(state, action)
6162

pacai/agents/scripted.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import typing
2+
13
import pacai.core.action
24
import pacai.core.agent
35
import pacai.core.gamestate
@@ -15,7 +17,7 @@ class ScriptedAgent(pacai.core.agent.Agent):
1517

1618
def __init__(self,
1719
actions: list[pacai.core.action.Action] | list[str] | str | None = None,
18-
**kwargs) -> None:
20+
**kwargs: typing.Any) -> None:
1921
super().__init__(**kwargs)
2022

2123
if (actions is None):

pacai/agents/searchproblem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import typing
23

34
import edq.util.time
45

@@ -31,7 +32,7 @@ def __init__(self,
3132
problem_cost: pacai.core.search.CostFunction | pacai.util.reflection.Reference | str = DEFAULT_PROBLEM_COST,
3233
solver: pacai.core.search.SearchProblemSolver | pacai.util.reflection.Reference | str = DEFAULT_SOLVER,
3334
heuristic: pacai.core.search.SearchHeuristic | pacai.util.reflection.Reference | str = DEFAULT_HEURISTIC,
34-
**kwargs) -> None:
35+
**kwargs: typing.Any) -> None:
3536
super().__init__(**kwargs)
3637

3738
claen_problem_class = pacai.util.reflection.resolve_and_fetch(type, problem)

pacai/agents/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
import typing
23

34
import pacai.agents.dummy
45
import pacai.core.action
@@ -17,7 +18,7 @@ def __init__(self,
1718
game_start_wait: float = 0.0,
1819
game_complete_wait: float = 0.0,
1920
get_action_wait: float = 0.0,
20-
**kwargs) -> None:
21+
**kwargs: typing.Any) -> None:
2122
super().__init__(**kwargs)
2223

2324
self._game_start_wait: float = float(game_start_wait)

pacai/agents/userinput.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import typing
2+
13
import pacai.core.action
24
import pacai.core.agent
35
import pacai.core.agentaction
@@ -10,7 +12,7 @@ class UserInputAgent(pacai.core.agent.Agent):
1012

1113
def __init__(self,
1214
remember_last_action: bool = True,
13-
**kwargs) -> None:
15+
**kwargs: typing.Any) -> None:
1416
super().__init__(**kwargs)
1517

1618
self._remember_last_action: bool = remember_last_action

pacai/capture/agents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DefensiveAgent(pacai.agents.greedy.GreedyFeatureAgent):
1616

1717
def __init__(self,
1818
override_weights: dict[str, float] | None = None,
19-
**kwargs) -> None:
19+
**kwargs: typing.Any) -> None:
2020
kwargs['feature_extractor_func'] = _extract_baseline_defensive_features
2121
super().__init__(**kwargs)
2222

@@ -46,7 +46,7 @@ class OffensiveAgent(pacai.agents.greedy.GreedyFeatureAgent):
4646

4747
def __init__(self,
4848
override_weights: dict[str, float] | None = None,
49-
**kwargs) -> None:
49+
**kwargs: typing.Any) -> None:
5050
kwargs['feature_extractor_func'] = _extract_baseline_offensive_features
5151
super().__init__(**kwargs)
5252

@@ -70,7 +70,7 @@ def _extract_baseline_defensive_features(
7070
state: pacai.core.gamestate.GameState,
7171
action: pacai.core.action.Action,
7272
agent: pacai.core.agent.Agent | None = None,
73-
**kwargs) -> pacai.core.features.FeatureDict:
73+
**kwargs: typing.Any) -> pacai.core.features.FeatureDict:
7474
agent = typing.cast(DefensiveAgent, agent)
7575
state = typing.cast(pacai.capture.gamestate.GameState, state)
7676

@@ -108,7 +108,7 @@ def _extract_baseline_offensive_features(
108108
state: pacai.core.gamestate.GameState,
109109
action: pacai.core.action.Action,
110110
agent: pacai.core.agent.Agent | None = None,
111-
**kwargs) -> pacai.core.features.FeatureDict:
111+
**kwargs: typing.Any) -> pacai.core.features.FeatureDict:
112112
agent = typing.cast(OffensiveAgent, agent)
113113
state = typing.cast(pacai.capture.gamestate.GameState, state)
114114

pacai/capture/bin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
RANDOM_BOARD_PREFIX: str = 'random'
1919

20-
def set_cli_args(parser: argparse.ArgumentParser, **kwargs) -> argparse.ArgumentParser:
20+
def set_cli_args(parser: argparse.ArgumentParser, **kwargs: typing.Any) -> argparse.ArgumentParser:
2121
"""
2222
Set Capture-specific CLI arguments.
2323
This is a sibling to init_from_args(), as the arguments set here can be interpreted there.
@@ -86,7 +86,7 @@ def get_additional_ui_options(args: argparse.Namespace) -> dict[str, typing.Any]
8686
'sprite_sheet_path': DEFAULT_SPRITE_SHEET,
8787
}
8888

89-
def log_capture_results(results: list[pacai.core.game.GameResult], winning_agent_indexes: set[int], prefix = '') -> None:
89+
def log_capture_results(results: list[pacai.core.game.GameResult], winning_agent_indexes: set[int], prefix: str = '') -> None:
9090
"""
9191
Log the result of running several games.
9292
"""

0 commit comments

Comments
 (0)