code: def _check_spec_register(spec: EnvSpec):
      """Checks whether the spec is valid to be registered. Helper function for `register`."""
      global registry
      latest_versioned_spec = max(
          (
              spec_
              for spec_ in registry.values()
              if spec_.namespace == spec.namespace
              and spec_.name == spec.name
              and spec_.version is not None
          ),
          key=lambda spec_: int(spec_.version),  # type: ignore
          default=None,
      )
  
      unversioned_spec = next(
          (
              spec_
              for spec_ in registry.values()
              if spec_.namespace == spec.namespace
              and spec_.name == spec.name
              and spec_.version is None
          ),
          None,
      )
  
      if unversioned_spec is not None and spec.version is not None:
          raise error.RegistrationError(
              "Can't register the versioned environment "
              f"`{spec.id}` when the unversioned environment "
              f"`{unversioned_spec.id}` of the same name already exists."
          )
      elif latest_versioned_spec is not None and spec.version is None:
          raise error.RegistrationError(
              "Can't register the unversioned environment "
              f"`{spec.id}` when the versioned environment "
              f"`{latest_versioned_spec.id}` of the same name "
              f"already exists. Note: the default behavior is "
              f"that `gym.make` with the unversioned environment "
              f"will return the latest versioned environment"
          )
  
imports: import contextlib
  import copy
  import difflib
  import importlib
  import importlib.util
  import re
  import sys
  import warnings
  from dataclasses import dataclass, field
  from typing import Callable, Dict, List, Optional, Sequence, SupportsFloat, Tuple, Union, overload
  import numpy
  from gym.wrappers import AutoResetWrapper, HumanRendering, OrderEnforcing, RenderCollection, TimeLimit
  from gym.wrappers.compatibility import EnvCompatibility
  from gym.wrappers.env_checker import PassiveEnvChecker
  from gym import Env, error, logger
label_desc: Use image node_id 24 for calling a global function with example usage: _check_spec_register(spec) without return types