Skip to content

Commit 728d492

Browse files
author
Chris Elion
authored
add pyupgrade to pre-commit and run (#4239)
1 parent 6dc68df commit 728d492

30 files changed

+49
-45
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ repos:
3939
# flake8-tidy-imports is used for banned-modules, not actually tidying
4040
additional_dependencies: [flake8-comprehensions==3.2.2, flake8-tidy-imports==4.1.0, flake8-bugbear==20.1.4]
4141

42+
- repo: https://github.com/asottile/pyupgrade
43+
rev: v2.7.0
44+
hooks:
45+
- id: pyupgrade
46+
args: [--py3-plus]
47+
exclude: .*barracuda.py
48+
4249
- repo: https://github.com/pre-commit/pre-commit-hooks
4350
rev: v2.5.0
4451
hooks:

gym-unity/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def run(self):
2323
tag = os.getenv("CIRCLE_TAG")
2424

2525
if tag != EXPECTED_TAG:
26-
info = "Git tag: {0} does not match the expected tag of this app: {1}".format(
26+
info = "Git tag: {} does not match the expected tag of this app: {}".format(
2727
tag, EXPECTED_TAG
2828
)
2929
sys.exit(info)

ml-agents-envs/mlagents_envs/communicator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mlagents_envs.communicator_objects.unity_input_pb2 import UnityInputProto
44

55

6-
class Communicator(object):
6+
class Communicator:
77
def __init__(self, worker_id=0, base_port=5005):
88
"""
99
Python side of the communication. Must be used in pair with the right Unity Communicator equivalent.

ml-agents-envs/mlagents_envs/communicator_objects/unity_to_external_pb2_grpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mlagents_envs.communicator_objects import unity_message_pb2 as mlagents__envs_dot_communicator__objects_dot_unity__message__pb2
55

66

7-
class UnityToExternalProtoStub(object):
7+
class UnityToExternalProtoStub:
88
# missing associated documentation comment in .proto file
99
pass
1010

@@ -21,7 +21,7 @@ def __init__(self, channel):
2121
)
2222

2323

24-
class UnityToExternalProtoServicer(object):
24+
class UnityToExternalProtoServicer:
2525
# missing associated documentation comment in .proto file
2626
pass
2727

ml-agents-envs/mlagents_envs/environment.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def behavior_specs(self) -> MappingType[str, BehaviorSpec]:
326326
def _assert_behavior_exists(self, behavior_name: str) -> None:
327327
if behavior_name not in self._env_specs:
328328
raise UnityActionException(
329-
"The group {0} does not correspond to an existing agent group "
330-
"in the environment".format(behavior_name)
329+
f"The group {behavior_name} does not correspond to an existing "
330+
f"agent group in the environment"
331331
)
332332

333333
def set_actions(self, behavior_name: BehaviorName, action: np.ndarray) -> None:
@@ -339,9 +339,9 @@ def set_actions(self, behavior_name: BehaviorName, action: np.ndarray) -> None:
339339
expected_shape = (len(self._env_state[behavior_name][0]), spec.action_size)
340340
if action.shape != expected_shape:
341341
raise UnityActionException(
342-
"The behavior {0} needs an input of dimension {1} for "
343-
"(<number of agents>, <action size>) but received input of "
344-
"dimension {2}".format(behavior_name, expected_shape, action.shape)
342+
f"The behavior {behavior_name} needs an input of dimension "
343+
f"{expected_shape} for (<number of agents>, <action size>) but "
344+
f"received input of dimension {action.shape}"
345345
)
346346
if action.dtype != expected_type:
347347
action = action.astype(expected_type)
@@ -357,10 +357,9 @@ def set_action_for_agent(
357357
expected_shape = (spec.action_size,)
358358
if action.shape != expected_shape:
359359
raise UnityActionException(
360-
f"The Agent {0} with BehaviorName {1} needs an input of dimension "
361-
f"{2} but received input of dimension {3}".format(
362-
agent_id, behavior_name, expected_shape, action.shape
363-
)
360+
f"The Agent {agent_id} with BehaviorName {behavior_name} needs "
361+
f"an input of dimension {expected_shape} but received input of "
362+
f"dimension {action.shape}"
364363
)
365364
expected_type = np.float32 if spec.is_action_continuous() else np.int32
366365
if action.dtype != expected_type:

ml-agents-envs/mlagents_envs/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ class UnityWorkerInUseException(UnityException):
7575

7676
def __init__(self, worker_id):
7777
message = self.MESSAGE_TEMPLATE.format(str(worker_id))
78-
super(UnityWorkerInUseException, self).__init__(message)
78+
super().__init__(message)

ml-agents-envs/mlagents_envs/rpc_communicator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def check_port(self, port):
8181
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
8282
try:
8383
s.bind(("localhost", port))
84-
except socket.error:
84+
except OSError:
8585
raise UnityWorkerInUseException(self.worker_id)
8686
finally:
8787
s.close()

ml-agents-envs/mlagents_envs/side_channel/environment_parameters_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SamplerTypes(IntEnum):
2222
MULTIRANGEUNIFORM = 2
2323

2424
def __init__(self) -> None:
25-
channel_id = uuid.UUID(("534c891e-810f-11ea-a9d0-822485860400"))
25+
channel_id = uuid.UUID("534c891e-810f-11ea-a9d0-822485860400")
2626
super().__init__(channel_id)
2727

2828
def on_message_received(self, msg: IncomingMessage) -> None:

ml-agents-envs/mlagents_envs/side_channel/float_properties_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FloatPropertiesChannel(SideChannel):
1313
def __init__(self, channel_id: uuid.UUID = None) -> None:
1414
self._float_properties: Dict[str, float] = {}
1515
if channel_id is None:
16-
channel_id = uuid.UUID(("60ccf7d0-4f7e-11ea-b238-784f4387d1f7"))
16+
channel_id = uuid.UUID("60ccf7d0-4f7e-11ea-b238-784f4387d1f7")
1717
super().__init__(channel_id)
1818

1919
def on_message_received(self, msg: IncomingMessage) -> None:

ml-agents-envs/mlagents_envs/side_channel/side_channel_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def process_side_channel_message(self, data: bytes) -> None:
3333
)
3434
if len(message_data) != message_len:
3535
raise UnityEnvironmentException(
36-
"The message received by the side channel {0} was "
36+
"The message received by the side channel {} was "
3737
"unexpectedly short. Make sure your Unity Environment "
3838
"sending side channel data properly.".format(channel_id)
3939
)

0 commit comments

Comments
 (0)