Skip to content

Commit 7c90c4d

Browse files
tewaldsrichardapowell
authored andcommitted
Various minor python 3 and 3.10 improvements.
PiperOrigin-RevId: 460481231
1 parent 84bbe4e commit 7c90c4d

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

pysc2/env/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pytype_library(
162162
"//pysc2/lib:units",
163163
"//pysc2/tests:dummy_observation",
164164
"@s2client_proto//s2clientprotocol:common_py_pb2",
165+
"@s2client_proto//s2clientprotocol:raw_py_pb2",
166+
"@s2client_proto//s2clientprotocol:sc2api_py_pb2",
165167
],
166168
)
167169

pysc2/env/lan_sc2_env.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class LanSC2Env(sc2_env.SC2Env):
203203
script, likely play_vs_agent.py.
204204
"""
205205

206-
def __init__(self, # pylint: disable=invalid-name
207-
_only_use_kwargs=None,
206+
def __init__(self,
207+
*,
208208
host="127.0.0.1",
209209
config_port=None,
210210
race=None,
@@ -232,7 +232,6 @@ def __init__(self, # pylint: disable=invalid-name
232232
height. If you specify size then both width and height will take that value.
233233
234234
Args:
235-
_only_use_kwargs: Don't pass args, only kwargs.
236235
host: Which ip to use. Either ipv4 or ipv6 localhost.
237236
config_port: Where to find the config port.
238237
race: Race for this agent.
@@ -260,9 +259,6 @@ def __init__(self, # pylint: disable=invalid-name
260259
ValueError: if the resolutions aren't specified correctly.
261260
ValueError: if the host or port are invalid.
262261
"""
263-
if _only_use_kwargs:
264-
raise ValueError("All arguments must be passed as keyword arguments.")
265-
266262
if host not in ("127.0.0.1", "::1"):
267263
raise ValueError("Bad host arguments. Must be a localhost")
268264
if not config_port:

pysc2/env/mock_sc2_env.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_method(self):
156156
"""
157157

158158
def __init__(self,
159-
_only_use_kwargs=None,
159+
*,
160160
map_name=None,
161161
players=None,
162162
agent_interface_format=None,
@@ -177,7 +177,6 @@ def __init__(self,
177177
"""Initializes an SC2TestEnv.
178178
179179
Args:
180-
_only_use_kwargs: Don't pass args, only kwargs.
181180
map_name: Map name. Ignored.
182181
players: A list of Agent and Bot instances that specify who will play.
183182
agent_interface_format: A sequence containing one AgentInterfaceFormat per
@@ -222,9 +221,6 @@ def __init__(self,
222221
del ensure_available_actions # Unused.
223222
del version # Unused.
224223

225-
if _only_use_kwargs:
226-
raise ValueError('All arguments must be passed as keyword arguments.')
227-
228224
if realtime:
229225
raise ValueError('realtime mode is not supported by the mock env.')
230226

pysc2/env/remote_sc2_env.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
"""A Starcraft II environment for playing using remote SC2 instances."""
1515

16-
import collections
16+
from typing import Sequence
1717

1818
from absl import logging
1919
from pysc2 import maps
@@ -39,8 +39,8 @@ class RemoteSC2Env(sc2_env.SC2Env):
3939
This assumes a 2 player game, and works best with play_vs_agent.py.
4040
"""
4141

42-
def __init__(self, # pylint: disable=invalid-name
43-
_only_use_kwargs=None,
42+
def __init__(self,
43+
*,
4444
map_name=None,
4545
save_map=True,
4646
host="127.0.0.1",
@@ -72,7 +72,6 @@ def __init__(self, # pylint: disable=invalid-name
7272
documentation for further detail.
7373
7474
Args:
75-
_only_use_kwargs: Don't pass args, only kwargs.
7675
map_name: Name of a SC2 map. Run bin/map_list to get the full list of
7776
known maps. Alternatively, pass a Map instance. Take a look at the
7877
docs in maps/README.md for more information on available maps.
@@ -108,9 +107,6 @@ def __init__(self, # pylint: disable=invalid-name
108107
ValueError: if the resolutions aren't specified correctly.
109108
ValueError: if lan_port is a sequence but its length != 4.
110109
"""
111-
if _only_use_kwargs:
112-
raise ValueError("All arguments must be passed as keyword arguments.")
113-
114110
if agent_interface_format is None:
115111
raise ValueError("Please specify agent_interface_format.")
116112

@@ -144,7 +140,7 @@ def __init__(self, # pylint: disable=invalid-name
144140
interface = self._get_interface(
145141
agent_interface_format=agent_interface_format, require_raw=visualize)
146142

147-
if isinstance(lan_port, collections.Sequence):
143+
if isinstance(lan_port, Sequence):
148144
if len(lan_port) != 4:
149145
raise ValueError("lan_port sequence must be of length 4")
150146
ports = lan_port[:]

pysc2/env/sc2_env.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class SC2Env(environment.Base):
9494
lib/features.py
9595
"""
9696

97-
def __init__(self, # pylint: disable=invalid-name
98-
_only_use_kwargs=None,
97+
def __init__(self,
98+
*,
9999
map_name=None,
100100
battle_net_map=False,
101101
players=None,
@@ -126,7 +126,6 @@ def __init__(self, # pylint: disable=invalid-name
126126
height. If you specify size then both width and height will take that value.
127127
128128
Args:
129-
_only_use_kwargs: Don't pass args, only kwargs.
130129
map_name: Name of a SC2 map. Run bin/map_list to get the full list of
131130
known maps. Alternatively, pass a Map instance. Take a look at the
132131
docs in maps/README.md for more information on available maps. Can
@@ -179,9 +178,6 @@ def __init__(self, # pylint: disable=invalid-name
179178
ValueError: if wrong number of players are requested for a map.
180179
ValueError: if the resolutions aren't specified correctly.
181180
"""
182-
if _only_use_kwargs:
183-
raise ValueError("All arguments must be passed as keyword arguments.")
184-
185181
if not players:
186182
raise ValueError("You must specify the list of players.")
187183

0 commit comments

Comments
 (0)