Skip to content

Commit 903cb80

Browse files
committed
Change typing.List and typing.Tuple to list and tuple equivalents
1 parent cd9a629 commit 903cb80

6 files changed

Lines changed: 45 additions & 48 deletions

File tree

src/pygambit/action.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Action:
108108
return Rational(py_string.decode("ascii"))
109109

110110
@property
111-
def plays(self) -> typing.List[Node]:
111+
def plays(self) -> list[Node]:
112112
"""Returns a list of all terminal `Node` objects consistent with it.
113113
"""
114114
return [

src/pygambit/behavmixed.pxi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MixedAction:
8181
def __len__(self) -> len:
8282
return len(self.infoset.actions)
8383

84-
def __iter__(self) -> typing.Iterator[typing.Tuple[Action, ProfileDType], None, None]:
84+
def __iter__(self) -> typing.Iterator[tuple[Action, ProfileDType], None, None]:
8585
"""Iterate over the probabilities assigned to actions by the mixed action.
8686

8787
.. versionadded:: 16.2.0
@@ -225,7 +225,7 @@ class MixedBehavior:
225225
def __len__(self) -> int:
226226
return len(self.player.actions)
227227

228-
def mixed_actions(self) -> typing.Iterator[typing.Tuple[Infoset, MixedAction], None, None]:
228+
def mixed_actions(self) -> typing.Iterator[tuple[Infoset, MixedAction], None, None]:
229229
"""Iterate over the mixed actions specified by the mixed behavior.
230230

231231
.. versionadded:: 16.2.0
@@ -240,7 +240,7 @@ class MixedBehavior:
240240
for infoset in self.player.infosets:
241241
yield infoset, self[infoset]
242242

243-
def __iter__(self) -> typing.Iterator[typing.Tuple[Action, ProfileDType], None, None]:
243+
def __iter__(self) -> typing.Iterator[tuple[Action, ProfileDType], None, None]:
244244
"""Iterate over the probabilities assigned to actions by the mixed behavior.
245245

246246
.. versionadded:: 16.2.0
@@ -387,7 +387,7 @@ class MixedBehaviorProfile:
387387
"""The game on which this mixed behavior profile is defined."""
388388
return self._game
389389

390-
def mixed_behaviors(self) -> typing.Iterator[typing.Tuple[Player, MixedBehavior], None, None]:
390+
def mixed_behaviors(self) -> typing.Iterator[tuple[Player, MixedBehavior], None, None]:
391391
"""Iterate over the mixed behaviors in the profile.
392392

393393
.. versionadded:: 16.2.0
@@ -402,7 +402,7 @@ class MixedBehaviorProfile:
402402
for player in self.game.players:
403403
yield player, self[player]
404404

405-
def mixed_actions(self) -> typing.Iterator[typing.Tuple[Infoset, MixedAction], None, None]:
405+
def mixed_actions(self) -> typing.Iterator[tuple[Infoset, MixedAction], None, None]:
406406
"""Iterate over the mixed actions specified by the profile.
407407

408408
.. versionadded:: 16.2.0
@@ -417,7 +417,7 @@ class MixedBehaviorProfile:
417417
for infoset in self.game.infosets:
418418
yield infoset, self[infoset]
419419

420-
def __iter__(self) -> typing.Iterator[typing.Tuple[Action, ProfileDType], None, None]:
420+
def __iter__(self) -> typing.Iterator[tuple[Action, ProfileDType], None, None]:
421421
"""Iterate over the probabilities assigned to actions by the profile.
422422

423423
.. versionadded:: 16.2.0

src/pygambit/game.pxi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class Game:
468468

469469
@classmethod
470470
def new_tree(cls,
471-
players: typing.List[str] | None = None,
471+
players: list[str] | None = None,
472472
title: str = "Untitled extensive game") -> Game:
473473
"""Create a new ``Game`` consisting of a trivial game tree,
474474
with one node, which is both root and terminal.
@@ -562,7 +562,7 @@ class Game:
562562
g.title = title
563563
return g
564564

565-
def to_arrays(self, dtype: typing.Type = Rational) -> typing.List[np.array]:
565+
def to_arrays(self, dtype: typing.Type = Rational) -> list[np.array]:
566566
"""Generate the payoff tables for players represented as numpy arrays.
567567

568568
Parameters
@@ -1475,7 +1475,7 @@ class Game:
14751475
def _resolve_nodes(self,
14761476
nodes: typing.Any,
14771477
funcname: str,
1478-
argname: str = "nodes") -> typing.List[Node]:
1478+
argname: str = "nodes") -> list[Node]:
14791479
"""Resolve an attempt to reference a subset of the nodes of the game of the game.
14801480

14811481
See `_resolve_node` for details on functionality.
@@ -1575,7 +1575,7 @@ class Game:
15751575

15761576
def append_move(self, nodes: Node | NodeReferenceSet,
15771577
player: Player | str,
1578-
actions: typing.List[str]) -> None:
1578+
actions: list[str]) -> None:
15791579
"""Add a move for `player` at terminal `nodes`. All elements of `nodes` become part of
15801580
a new information set, with actions labeled according to `actions`.
15811581

@@ -1753,7 +1753,7 @@ class Game:
17531753
self.game.deref().DeleteTree(resolved_node.node)
17541754

17551755
def add_action(self,
1756-
infoset: typing.Infoset | str,
1756+
infoset: Infoset | str,
17571757
before: Action | str | None = None) -> None:
17581758
"""Add an action at the information set `infoset`. If `before` is not null, the new
17591759
action is inserted before `before`.

src/pygambit/infoset.pxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Infoset:
167167
return InfosetActions.wrap(self.infoset)
168168

169169
@property
170-
def own_prior_actions(self) -> typing.List[Action | None]:
170+
def own_prior_actions(self) -> list[Action | None]:
171171
"""The set of actions taken by the player immediately preceding the member nodes
172172
in the information set.
173173

@@ -216,7 +216,7 @@ class Infoset:
216216
return Player.wrap(self.infoset.deref().GetPlayer())
217217

218218
@property
219-
def plays(self) -> typing.List[Node]:
219+
def plays(self) -> list[Node]:
220220
"""Returns a list of all terminal `Node` objects consistent with it.
221221
"""
222222
return [

src/pygambit/nash.pxi

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,120 +25,117 @@ from cython.operator cimport dereference as deref
2525
from libcpp.list cimport list as stdlist
2626

2727

28-
import typing
29-
30-
3128
@cython.cfunc
3229
def _convert_mspd(
3330
inlist: stdlist[c_MixedStrategyProfile[float]]
34-
) -> typing.List[MixedStrategyProfile[double]]:
31+
) -> list[MixedStrategyProfile[double]]:
3532
return [MixedStrategyProfileDouble.wrap(profile)
3633
for profile in make_list_of_pointer(inlist)]
3734

3835

3936
@cython.cfunc
4037
def _convert_mspr(
4138
inlist: stdlist[c_MixedStrategyProfile[c_Rational]]
42-
) -> typing.List[MixedStrategyProfile[c_Rational]]:
39+
) -> list[MixedStrategyProfile[c_Rational]]:
4340
return [MixedStrategyProfileRational.wrap(profile)
4441
for profile in make_list_of_pointer(inlist)]
4542

4643

4744
@cython.cfunc
4845
def _convert_mbpd(
4946
inlist: stdlist[c_MixedBehaviorProfile[float]]
50-
) -> typing.List[MixedBehaviorProfile[double]]:
47+
) -> list[MixedBehaviorProfile[double]]:
5148
return [MixedBehaviorProfileDouble.wrap(profile)
5249
for profile in make_list_of_pointer(inlist)]
5350

5451

5552
@cython.cfunc
5653
def _convert_mbpr(
5754
inlist: stdlist[c_MixedBehaviorProfile[c_Rational]]
58-
) -> typing.List[MixedBehaviorProfile[c_Rational]]:
55+
) -> list[MixedBehaviorProfile[c_Rational]]:
5956
return [MixedBehaviorProfileRational.wrap(profile)
6057
for profile in make_list_of_pointer(inlist)]
6158

6259

63-
def _enumpure_strategy_solve(game: Game) -> typing.List[MixedStrategyProfile[c_Rational]]:
60+
def _enumpure_strategy_solve(game: Game) -> list[MixedStrategyProfile[c_Rational]]:
6461
return _convert_mspr(EnumPureStrategySolve(game.game))
6562

6663

67-
def _enumpure_agent_solve(game: Game) -> typing.List[MixedBehaviorProfileRational]:
64+
def _enumpure_agent_solve(game: Game) -> list[MixedBehaviorProfileRational]:
6865
return _convert_mbpr(EnumPureAgentSolve(game.game))
6966

7067

71-
def _enummixed_strategy_solve_double(game: Game) -> typing.List[MixedStrategyProfileDouble]:
68+
def _enummixed_strategy_solve_double(game: Game) -> list[MixedStrategyProfileDouble]:
7269
return _convert_mspd(EnumMixedStrategySolve[double](game.game))
7370

7471

75-
def _enummixed_strategy_solve_rational(game: Game) -> typing.List[MixedStrategyProfileRational]:
72+
def _enummixed_strategy_solve_rational(game: Game) -> list[MixedStrategyProfileRational]:
7673
return _convert_mspr(EnumMixedStrategySolve[c_Rational](game.game))
7774

7875

7976
def _lcp_behavior_solve_double(
8077
game: Game, stop_after: int, max_depth: int
81-
) -> typing.List[MixedBehaviorProfileDouble]:
78+
) -> list[MixedBehaviorProfileDouble]:
8279
return _convert_mbpd(LcpBehaviorSolve[double](game.game, stop_after, max_depth))
8380

8481

8582
def _lcp_behavior_solve_rational(
8683
game: Game, stop_after: int, max_depth: int
87-
) -> typing.List[MixedBehaviorProfileRational]:
84+
) -> list[MixedBehaviorProfileRational]:
8885
return _convert_mbpr(LcpBehaviorSolve[c_Rational](game.game, stop_after, max_depth))
8986

9087

9188
def _lcp_strategy_solve_double(
9289
game: Game, stop_after: int, max_depth: int
93-
) -> typing.List[MixedStrategyProfileDouble]:
90+
) -> list[MixedStrategyProfileDouble]:
9491
return _convert_mspd(LcpStrategySolve[double](game.game, stop_after, max_depth))
9592

9693

9794
def _lcp_strategy_solve_rational(
9895
game: Game, stop_after: int, max_depth: int
99-
) -> typing.List[MixedStrategyProfileRational]:
96+
) -> list[MixedStrategyProfileRational]:
10097
return _convert_mspr(LcpStrategySolve[c_Rational](game.game, stop_after, max_depth))
10198

10299

103-
def _lp_behavior_solve_double(game: Game) -> typing.List[MixedBehaviorProfileDouble]:
100+
def _lp_behavior_solve_double(game: Game) -> list[MixedBehaviorProfileDouble]:
104101
return _convert_mbpd(LpBehaviorSolve[double](game.game))
105102

106103

107-
def _lp_behavior_solve_rational(game: Game) -> typing.List[MixedBehaviorProfileRational]:
104+
def _lp_behavior_solve_rational(game: Game) -> list[MixedBehaviorProfileRational]:
108105
return _convert_mbpr(LpBehaviorSolve[c_Rational](game.game))
109106

110107

111-
def _lp_strategy_solve_double(game: Game) -> typing.List[MixedStrategyProfileDouble]:
108+
def _lp_strategy_solve_double(game: Game) -> list[MixedStrategyProfileDouble]:
112109
return _convert_mspd(LpStrategySolve[double](game.game))
113110

114111

115-
def _lp_strategy_solve_rational(game: Game) -> typing.List[MixedStrategyProfileRational]:
112+
def _lp_strategy_solve_rational(game: Game) -> list[MixedStrategyProfileRational]:
116113
return _convert_mspr(LpStrategySolve[c_Rational](game.game))
117114

118115

119116
def _liap_strategy_solve(start: MixedStrategyProfileDouble,
120117
maxregret: float,
121-
maxiter: int) -> typing.List[MixedStrategyProfileDouble]:
118+
maxiter: int) -> list[MixedStrategyProfileDouble]:
122119
return _convert_mspd(LiapStrategySolve(deref(start.profile), maxregret, maxiter))
123120

124121

125122
def _liap_behavior_solve(start: MixedBehaviorProfileDouble,
126123
maxregret: float,
127-
maxiter: int) -> typing.List[MixedBehaviorProfileDouble]:
124+
maxiter: int) -> list[MixedBehaviorProfileDouble]:
128125
return _convert_mbpd(LiapBehaviorSolve(deref(start.profile), maxregret, maxiter))
129126

130127

131128
def _simpdiv_strategy_solve(
132129
start: MixedStrategyProfileRational, maxregret: Rational, gridstep: int, leash: int
133-
) -> typing.List[MixedStrategyProfileRational]:
130+
) -> list[MixedStrategyProfileRational]:
134131
return _convert_mspr(SimpdivStrategySolve(deref(start.profile),
135132
to_rational(str(maxregret).encode("ascii")),
136133
gridstep, leash))
137134

138135

139136
def _ipa_strategy_solve(
140137
pert: MixedStrategyProfileDouble
141-
) -> typing.List[MixedStrategyProfileDouble]:
138+
) -> list[MixedStrategyProfileDouble]:
142139
try:
143140
return _convert_mspd(IPAStrategySolve(deref(pert.profile)))
144141
except RuntimeError as e:
@@ -153,7 +150,7 @@ def _gnm_strategy_solve(
153150
steps: int,
154151
local_newton_interval: int,
155152
local_newton_maxits: int,
156-
) -> typing.List[MixedStrategyProfileDouble]:
153+
) -> list[MixedStrategyProfileDouble]:
157154
try:
158155
return _convert_mspd(GNMStrategySolve(deref(pert.profile), end_lambda,
159156
steps, local_newton_interval, local_newton_maxits))
@@ -163,7 +160,7 @@ def _gnm_strategy_solve(
163160
raise
164161

165162

166-
def _nashsupport_strategy_solve(game: Game) -> typing.List[StrategySupportProfile]:
163+
def _nashsupport_strategy_solve(game: Game) -> list[StrategySupportProfile]:
167164
return [
168165
StrategySupportProfile.wrap(support)
169166
for support in make_list_of_pointer(
@@ -176,27 +173,27 @@ def _enumpoly_strategy_solve(
176173
game: Game,
177174
stop_after: int,
178175
maxregret: float,
179-
) -> typing.List[MixedStrategyProfileDouble]:
176+
) -> list[MixedStrategyProfileDouble]:
180177
return _convert_mspd(EnumPolyStrategySolve(game.game, stop_after, maxregret))
181178

182179

183180
def _enumpoly_behavior_solve(
184181
game: Game,
185182
stop_after: int,
186183
maxregret: float,
187-
) -> typing.List[MixedBehaviorProfileDouble]:
184+
) -> list[MixedBehaviorProfileDouble]:
188185
return _convert_mbpd(EnumPolyBehaviorSolve(game.game, stop_after, maxregret))
189186

190187

191188
def _logit_strategy_solve(
192189
game: Game, maxregret: float, first_step: float, max_accel: float,
193-
) -> typing.List[MixedStrategyProfileDouble]:
190+
) -> list[MixedStrategyProfileDouble]:
194191
return _convert_mspd(LogitStrategySolveWrapper(game.game, maxregret, first_step, max_accel))
195192

196193

197194
def _logit_behavior_solve(
198195
game: Game, maxregret: float, first_step: float, max_accel: float,
199-
) -> typing.List[MixedBehaviorProfileDouble]:
196+
) -> list[MixedBehaviorProfileDouble]:
200197
return _convert_mbpd(LogitBehaviorSolveWrapper(game.game, maxregret, first_step, max_accel))
201198

202199

@@ -261,9 +258,9 @@ def _logit_strategy_estimate(profile: MixedStrategyProfileDouble,
261258

262259

263260
def _logit_strategy_lambda(game: Game,
264-
lam: float | typing.List[float],
261+
lam: float | list[float],
265262
first_step: float = .03,
266-
max_accel: float = 1.1) -> typing.List[LogitQREMixedStrategyProfile]:
263+
max_accel: float = 1.1) -> list[LogitQREMixedStrategyProfile]:
267264
"""Compute the first QRE encountered along the principal branch of the strategic
268265
game corresponding to lambda value `lam`.
269266
"""
@@ -342,9 +339,9 @@ def _logit_behavior_estimate(profile: MixedBehaviorProfileDouble,
342339

343340

344341
def _logit_behavior_lambda(game: Game,
345-
lam: float | typing.List[float],
342+
lam: float | list[float],
346343
first_step: float = .03,
347-
max_accel: float = 1.1) -> typing.List[LogitQREMixedBehaviorProfile]:
344+
max_accel: float = 1.1) -> list[LogitQREMixedBehaviorProfile]:
348345
"""Compute the first QRE encountered along the principal branch of the extensive
349346
game corresponding to lambda value `lam`.
350347
"""

src/pygambit/node.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Node:
255255
return Outcome.wrap(self.node.deref().GetOutcome())
256256

257257
@property
258-
def plays(self) -> typing.List[Node]:
258+
def plays(self) -> list[Node]:
259259
"""Returns a list of all terminal `Node` objects consistent with it.
260260
"""
261261
return [Node.wrap(n) for n in self.node.deref().GetGame().deref().GetPlays(self.node)]

0 commit comments

Comments
 (0)