From aca1e458bee9907cae8da86cffdf7ab3f71f4f6b Mon Sep 17 00:00:00 2001 From: Omar Younis Date: Thu, 23 Nov 2023 16:06:09 -0500 Subject: [PATCH 1/4] fix kwargs in register --- gymnasium/envs/registration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gymnasium/envs/registration.py b/gymnasium/envs/registration.py index 711d5f20e..807a5148c 100644 --- a/gymnasium/envs/registration.py +++ b/gymnasium/envs/registration.py @@ -621,7 +621,7 @@ def register( max_episode_steps=max_episode_steps, order_enforce=order_enforce, disable_env_checker=disable_env_checker, - **kwargs, + kwargs=kwargs, additional_wrappers=additional_wrappers, vector_entry_point=vector_entry_point, ) From 586dd6e7d08f651ab40f67122b1c18f552fe3f15 Mon Sep 17 00:00:00 2001 From: Omar Younis Date: Thu, 23 Nov 2023 16:11:24 -0500 Subject: [PATCH 2/4] fix tests --- tests/envs/registration/test_register.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/envs/registration/test_register.py b/tests/envs/registration/test_register.py index 918310b50..e0eca87a4 100644 --- a/tests/envs/registration/test_register.py +++ b/tests/envs/registration/test_register.py @@ -19,20 +19,16 @@ def register_registration_testing_envs(): gym.register( id=env_id, entry_point="tests.envs.registration.utils_envs:ArgumentEnv", - kwargs={ - "arg1": "arg1", - "arg2": "arg2", - "arg3": "arg3", - }, + arg1="arg1", + arg2="arg2", + arg3="arg3", ) gym.register( id=f"{namespace}/{unversioned_name}", entry_point="tests.env.utils_envs:ArgumentEnv", - kwargs={ - "arg1": "arg1", - "arg2": "arg2", - "arg3": "arg3", - }, + arg1="arg1", + arg2="arg2", + arg3="arg3", ) yield From 7784125e11148aa46c62eac12d9973dabd839871 Mon Sep 17 00:00:00 2001 From: Omar Younis Date: Thu, 23 Nov 2023 16:25:45 -0500 Subject: [PATCH 3/4] implement second option (no bc) --- gymnasium/envs/registration.py | 4 ++-- tests/envs/registration/test_register.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gymnasium/envs/registration.py b/gymnasium/envs/registration.py index 807a5148c..64570bc9c 100644 --- a/gymnasium/envs/registration.py +++ b/gymnasium/envs/registration.py @@ -567,7 +567,7 @@ def register( disable_env_checker: bool = False, additional_wrappers: tuple[WrapperSpec, ...] = (), vector_entry_point: VectorEnvCreator | str | None = None, - **kwargs: Any, + kwargs: dict = {}, ): """Registers an environment in gymnasium with an ``id`` to use with :meth:`gymnasium.make` with the ``entry_point`` being a string or callable for creating the environment. @@ -587,7 +587,7 @@ def register( disable_env_checker: If to disable the :class:`gymnasium.wrappers.PassiveEnvChecker` to the environment. additional_wrappers: Additional wrappers to apply the environment. vector_entry_point: The entry point for creating the vector environment - **kwargs: arbitrary keyword arguments which are passed to the environment constructor on initialisation. + kwargs: arbitrary keyword arguments which are passed to the environment constructor on initialisation. Changelogs: v1.0.0 - `autoreset` and `apply_api_compatibility` parameter was removed diff --git a/tests/envs/registration/test_register.py b/tests/envs/registration/test_register.py index e0eca87a4..918310b50 100644 --- a/tests/envs/registration/test_register.py +++ b/tests/envs/registration/test_register.py @@ -19,16 +19,20 @@ def register_registration_testing_envs(): gym.register( id=env_id, entry_point="tests.envs.registration.utils_envs:ArgumentEnv", - arg1="arg1", - arg2="arg2", - arg3="arg3", + kwargs={ + "arg1": "arg1", + "arg2": "arg2", + "arg3": "arg3", + }, ) gym.register( id=f"{namespace}/{unversioned_name}", entry_point="tests.env.utils_envs:ArgumentEnv", - arg1="arg1", - arg2="arg2", - arg3="arg3", + kwargs={ + "arg1": "arg1", + "arg2": "arg2", + "arg3": "arg3", + }, ) yield From a5209ab86343344c264ecf730a800da1e0891990 Mon Sep 17 00:00:00 2001 From: Omar Younis Date: Fri, 24 Nov 2023 19:34:33 -0500 Subject: [PATCH 4/4] remove mutable default --- gymnasium/envs/registration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gymnasium/envs/registration.py b/gymnasium/envs/registration.py index 64570bc9c..515c097e4 100644 --- a/gymnasium/envs/registration.py +++ b/gymnasium/envs/registration.py @@ -567,7 +567,7 @@ def register( disable_env_checker: bool = False, additional_wrappers: tuple[WrapperSpec, ...] = (), vector_entry_point: VectorEnvCreator | str | None = None, - kwargs: dict = {}, + kwargs: dict | None = None, ): """Registers an environment in gymnasium with an ``id`` to use with :meth:`gymnasium.make` with the ``entry_point`` being a string or callable for creating the environment. @@ -598,6 +598,8 @@ def register( global registry, current_namespace ns, name, version = parse_env_id(id) + if kwargs is None: + kwargs = dict() if current_namespace is not None: if ( kwargs.get("namespace") is not None