11from __future__ import annotations
22
33import sys
4- from typing import Any , Literal , Optional , Union
4+ from typing import Any , Literal
55
66import ale_py
77import gymnasium
@@ -35,14 +35,14 @@ class AtariEnv(gymnasium.Env, utils.EzPickle):
3535 def __init__ (
3636 self ,
3737 game : str ,
38- mode : Optional [ int ] = None ,
39- difficulty : Optional [ int ] = None ,
38+ mode : int | None = None ,
39+ difficulty : int | None = None ,
4040 obs_type : Literal ["rgb" , "grayscale" , "ram" ] = "rgb" ,
41- frameskip : Union [ tuple [int , int ], int ] = 4 ,
41+ frameskip : tuple [int , int ] | int = 4 ,
4242 repeat_action_probability : float = 0.25 ,
4343 full_action_space : bool = False ,
44- max_num_frames_per_episode : Optional [ int ] = None ,
45- render_mode : Optional [ Literal ["human" , "rgb_array" ]] = None ,
44+ max_num_frames_per_episode : int | None = None ,
45+ render_mode : Literal ["human" , "rgb_array" ] | None = None ,
4646 ):
4747 """
4848 Initialize the ALE for Gymnasium.
@@ -96,11 +96,11 @@ def __init__(
9696 )
9797 elif isinstance (frameskip , tuple ) and frameskip [0 ] > frameskip [1 ]:
9898 raise error .Error (
99- f "Invalid stochastic frameskip, lower bound is greater than upper bound."
99+ "Invalid stochastic frameskip, lower bound is greater than upper bound."
100100 )
101101 elif isinstance (frameskip , tuple ) and frameskip [0 ] <= 0 :
102102 raise error .Error (
103- f "Invalid stochastic frameskip lower bound is greater than upper bound."
103+ "Invalid stochastic frameskip lower bound is greater than upper bound."
104104 )
105105
106106 if render_mode is not None and render_mode not in {"rgb_array" , "human" }:
@@ -176,7 +176,7 @@ def __init__(
176176 else :
177177 raise error .Error (f"Unrecognized observation type: { self ._obs_type } " )
178178
179- def seed_game (self , seed : Optional [ int ] = None ) -> tuple [int , int ]:
179+ def seed_game (self , seed : int | None = None ) -> tuple [int , int ]:
180180 """Seeds the internal and ALE RNG."""
181181 ss = np .random .SeedSequence (seed )
182182 np_seed , ale_seed = ss .generate_state (n_words = 2 )
@@ -196,8 +196,8 @@ def load_game(self) -> None:
196196 def reset ( # pyright: ignore[reportIncompatibleMethodOverride]
197197 self ,
198198 * ,
199- seed : Optional [ int ] = None ,
200- options : Optional [ dict [str , Any ]] = None ,
199+ seed : int | None = None ,
200+ options : dict [str , Any ] | None = None ,
201201 ) -> tuple [np .ndarray , AtariEnvStepMetadata ]:
202202 """Resets environment and returns initial observation."""
203203 super ().reset (seed = seed , options = options )
@@ -253,7 +253,7 @@ def step( # pyright: ignore[reportIncompatibleMethodOverride]
253253
254254 return self ._get_obs (), reward , is_terminal , is_truncated , self ._get_info ()
255255
256- def render (self ) -> Optional [ np .ndarray ] :
256+ def render (self ) -> np .ndarray | None :
257257 """
258258 Render is not supported by ALE. We use a paradigm similar to
259259 Gym3 which allows you to specify `render_mode` during construction.
0 commit comments