2121def import_from_path (path : str ) -> callable :
2222 """
2323 Util function to import and instantiate a class, then return a specific method.
24- For example, given `browsergym.core.action.highlevel.HighLevelActionSet.to_python_code`,
25- this will instantiate `HighLevelActionSet` and return its `to_python_code` method.
26-
27- :param path: Path to the method
28- :type path: str
29- :raises ModuleNotFoundError: If the module cannot be imported
30- :return: The method
31- :rtype: callable
24+
25+ Args:
26+ path (str): Path to the method, e.g., 'browsergym.core.action.highlevel.HighLevelActionSet.to_python_code'.
27+
28+ Raises:
29+ ModuleNotFoundError: If the module cannot be imported.
30+
31+ Returns:
32+ callable: The method.
3233 """
3334
3435 parts = path .split ("." )
@@ -63,10 +64,11 @@ def make_json_safe(obj: Any) -> Any:
6364 Util function to convert numpy arrays and other non-JSON-serializable objects to JSON-serializable objects.
6465 Specifically, we convert numpy arrays to base64 encoded strings so that payloads are of reasonable size.
6566
66- :param obj: Object to convert
67- :type obj: Any
68- :return: JSON-serializable object
69- :rtype: Any
67+ Args:
68+ obj (Any): Object to convert
69+
70+ Returns:
71+ Any: JSON-serializable object
7072 """
7173 if isinstance (obj , np .ndarray ):
7274 # convert to base64
@@ -122,21 +124,19 @@ def set_info(
122124 seed : int ,
123125 action_mapping_fn : str ,
124126 exp_dir : str ,
125- ):
126- """Set the environment info.
127-
128- :param benchmark_name: Name of the benchmark
129- :type benchmark_name: str
130- :param task_name: Name of the task
131- :type task_name: str
132- :param seed: Seed of the task.
133- :type seed: int
134- :param action_mapping_fn: Action mapping function
135- :type action_mapping_fn: str
136- :param exp_dir: Directory for experiment
137- :type exp_dir: str
138- :return: Dictionary with status
139- :rtype: dict
127+ ) -> dict :
128+ """
129+ Set the environment info.
130+
131+ Args:
132+ benchmark_name (str): Name of the benchmark
133+ task_name (str): Name of the task
134+ seed (int): Seed of the task
135+ action_mapping_fn (str): Action mapping function
136+ exp_dir (str): Directory for experiment
137+
138+ Returns:
139+ dict: Dictionary with status
140140 """
141141 if self .info_set :
142142 return make_json_safe (
@@ -167,10 +167,11 @@ def set_info(
167167 )
168168
169169 def get_info (self ) -> dict :
170- """Get the environment info
170+ """
171+ Get the environment info.
171172
172- :return: Dictionary with info
173- :rtype: dict
173+ Returns:
174+ dict: Dictionary with info
174175 """
175176 if not self .info_set :
176177 return make_json_safe (
@@ -192,10 +193,11 @@ def get_info(self) -> dict:
192193 )
193194
194195 def unset_info (self ) -> dict :
195- """Unset the environment info
196+ """
197+ Unset the environment info.
196198
197- :return: Dictionary with status
198- :rtype: dict
199+ Returns:
200+ dict: Dictionary with status
199201 """
200202 if not self .info_set :
201203 return make_json_safe (
@@ -218,10 +220,11 @@ def unset_info(self) -> dict:
218220 )
219221
220222 def status (self ) -> dict :
221- """Get the environment status
223+ """
224+ Get the environment status.
222225
223- :return: Dictionary with status
224- :rtype: dict
226+ Returns:
227+ dict: Dictionary with status
225228 """
226229 return make_json_safe (
227230 {
@@ -236,8 +239,8 @@ def prepare_benchmark(self) -> dict:
236239 """
237240 Prepare the benchmark environment.
238241
239- :return: Dictionary with status
240- :rtype: dict
242+ Returns:
243+ dict: Dictionary with status
241244 """
242245 if not self .info_set :
243246 return make_json_safe (
@@ -272,10 +275,11 @@ def prepare_benchmark(self) -> dict:
272275 )
273276
274277 def reload_task (self ) -> dict :
275- """Reload the task
278+ """
279+ Reload the task.
276280
277- :return: Dictionary with status
278- :rtype: dict
281+ Returns:
282+ dict: Dictionary with status
279283 """
280284 if not self .info_set :
281285 return make_json_safe (
@@ -311,10 +315,11 @@ def reload_task(self) -> dict:
311315 )
312316
313317 def reset (self ) -> dict :
314- """Reset the environment
318+ """
319+ Reset the environment.
315320
316- :return: Dictionary with obs and info
317- :rtype: dict
321+ Returns:
322+ dict: Dictionary with obs and info
318323 """
319324 if not self .info_set :
320325 return make_json_safe (
@@ -348,12 +353,14 @@ def reset(self) -> dict:
348353 )
349354
350355 def step (self , action : str ) -> dict :
351- """Step the environment
356+ """
357+ Step the environment.
358+
359+ Args:
360+ action (str): Action to take
352361
353- :param action: Action to take
354- :type action: str
355- :return: Dictionary with obs, reward, terminated, truncated and info
356- :rtype: dict
362+ Returns:
363+ dict: Dictionary with obs, reward, terminated, truncated and info
357364 """
358365 if self .env is None :
359366 return make_json_safe (
@@ -380,10 +387,11 @@ def step(self, action: str) -> dict:
380387 )
381388
382389 def get_obs (self ) -> dict :
383- """Get the last observation
390+ """
391+ Get the last observation.
384392
385- :return: Dictionary with obs and info
386- :rtype: dict
393+ Returns:
394+ dict: Dictionary with obs and info
387395 """
388396 if self .env is None :
389397 return make_json_safe (
@@ -402,10 +410,11 @@ def get_obs(self) -> dict:
402410 )
403411
404412 def close (self ) -> dict :
405- """Close the environment
413+ """
414+ Close the environment.
406415
407- :return: Dictionary with status
408- :rtype: dict
416+ Returns:
417+ dict: Dictionary with status
409418 """
410419 if self .env is None :
411420 return make_json_safe (
@@ -429,14 +438,15 @@ def close(self) -> dict:
429438
430439# --- FastAPI endpoints ---
431440@app .post ("/set_info" )
432- def set_info (req : SetInfoRequest ):
441+ def set_info (req : SetInfoRequest ) -> dict :
433442 """
434443 Set the environment info.
435444
436- :param req: Request containing environment info
437- :type req: SetInfoRequest
438- :return: Dictionary with status
439- :rtype: dict
445+ Args:
446+ req (SetInfoRequest): Request containing environment info
447+
448+ Returns:
449+ dict: Dictionary with status
440450 """
441451 return env .set_info (
442452 benchmark_name = req .benchmark_name ,
@@ -452,8 +462,8 @@ def get_info() -> dict:
452462 """
453463 Get the environment info.
454464
455- :return: Dictionary with info
456- :rtype: dict
465+ Returns:
466+ dict: Dictionary with info
457467 """
458468 return env .get_info ()
459469
@@ -463,8 +473,8 @@ def unset_info() -> dict:
463473 """
464474 Unset the environment info.
465475
466- :return: Dictionary with status
467- :rtype: dict
476+ Returns:
477+ dict: Dictionary with status
468478 """
469479 return env .unset_info ()
470480
@@ -474,8 +484,8 @@ def status() -> dict:
474484 """
475485 Get the status of the environment.
476486
477- :return: Dictionary with status
478- :rtype: dict
487+ Returns:
488+ dict: Dictionary with status
479489 """
480490 return env .status ()
481491
@@ -485,8 +495,8 @@ def prepare_benchmark() -> dict:
485495 """
486496 Prepare the benchmark.
487497
488- :return: Dictionary with status
489- :rtype: dict
498+ Returns:
499+ dict: Dictionary with status
490500 """
491501 return env .prepare_benchmark ()
492502
@@ -496,8 +506,8 @@ def reload_task() -> dict:
496506 """
497507 Reload the task.
498508
499- :return: Dictionary with status
500- :rtype: dict
509+ Returns:
510+ dict: Dictionary with status
501511 """
502512 return env .reload_task ()
503513
@@ -507,8 +517,8 @@ def reset() -> dict:
507517 """
508518 Reset the environment.
509519
510- :return: Dictionary with status
511- :rtype: dict
520+ Returns:
521+ dict: Dictionary with status
512522 """
513523 return env .reset ()
514524
@@ -518,10 +528,11 @@ def step(req: StepRequest) -> dict:
518528 """
519529 Step the environment.
520530
521- :param req: Request containing action
522- :type req: StepRequest
523- :return: Dictionary with obs, reward, terminated, truncated and info
524- :rtype: dict
531+ Args:
532+ req (StepRequest): Request containing action
533+
534+ Returns:
535+ dict: Dictionary with obs, reward, terminated, truncated and info
525536 """
526537 return env .step (action = req .action )
527538
@@ -531,8 +542,8 @@ def get_obs() -> dict:
531542 """
532543 Get the last observation.
533544
534- :return: Dictionary with obs and info
535- :rtype: dict
545+ Returns:
546+ dict: Dictionary with obs and info
536547 """
537548 return env .get_obs ()
538549
@@ -542,8 +553,8 @@ def close() -> dict:
542553 """
543554 Close the environment.
544555
545- :return: Dictionary with status
546- :rtype: dict
556+ Returns:
557+ dict: Dictionary with status
547558 """
548559 return env .close ()
549560
0 commit comments