mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-31 18:12:53 +00:00
Py36+ syntax in gym/utils: derived by running pyupgrade --py36-plus gym/utils/**.py
and flynt gym --ll 120
(#2472)
Co-authored-by: Ilya Kamen <ilya.kamenshchikov@bosch.com>
This commit is contained in:
@@ -10,9 +10,7 @@ from gym import error
|
||||
|
||||
def np_random(seed=None):
|
||||
if seed is not None and not (isinstance(seed, int) and 0 <= seed):
|
||||
raise error.Error(
|
||||
"Seed must be a non-negative integer or omitted, not {}".format(seed)
|
||||
)
|
||||
raise error.Error(f"Seed must be a non-negative integer or omitted, not {seed}")
|
||||
|
||||
seed = create_seed(seed)
|
||||
|
||||
@@ -65,7 +63,7 @@ def create_seed(a=None, max_bytes=8):
|
||||
elif isinstance(a, int):
|
||||
a = a % 2 ** (8 * max_bytes)
|
||||
else:
|
||||
raise error.Error("Invalid type for seed: {} ({})".format(type(a), a))
|
||||
raise error.Error(f"Invalid type for seed: {type(a)} ({a})")
|
||||
|
||||
return a
|
||||
|
||||
@@ -76,7 +74,7 @@ def _bigint_from_bytes(bytes):
|
||||
padding = sizeof_int - len(bytes) % sizeof_int
|
||||
bytes += b"\0" * padding
|
||||
int_count = int(len(bytes) / sizeof_int)
|
||||
unpacked = struct.unpack("{}I".format(int_count), bytes)
|
||||
unpacked = struct.unpack(f"{int_count}I", bytes)
|
||||
accum = 0
|
||||
for i, val in enumerate(unpacked):
|
||||
accum += 2 ** (sizeof_int * 8 * i) * val
|
||||
@@ -86,7 +84,7 @@ def _bigint_from_bytes(bytes):
|
||||
def _int_list_from_bigint(bigint):
|
||||
# Special case 0
|
||||
if bigint < 0:
|
||||
raise error.Error("Seed must be non-negative, not {}".format(bigint))
|
||||
raise error.Error(f"Seed must be non-negative, not {bigint}")
|
||||
elif bigint == 0:
|
||||
return [0]
|
||||
|
||||
|
Reference in New Issue
Block a user