code: def _to_scope(
      location: scope_types,
  ) -> Optional[Union[List[MapRegion], MapRegion]]:
      if location is None:
          return None
  
      def _make_region(
          obj: Union[str, Geocodes]
      ) -> Optional[MapRegion]:
          if isinstance(obj, Geocodes):
              return MapRegion.scope(obj.unique_ids())
  
          if isinstance(obj, str):
              return MapRegion.with_name(obj)
  
          raise ValueError(
              "Unsupported scope type. Expected Geocoder, str or list, but was `{}`".format(
                  type(obj)
              )
          )
  
      if isinstance(location, list):
          return [_make_region(obj) for obj in location]
  
      return _make_region(location)
  
imports: from collections import namedtuple
  from collections.abc import Iterable
  from typing import Union, List, Optional, Dict
  from pandas import Series
  from .geocodes import _to_level_kind, request_types, Geocodes, _raise_exception, _ensure_is_list
  from .gis.geocoding_service import GeocodingService
  from .gis.geometry import GeoRect, GeoPoint
  from .gis.request import RequestBuilder, GeocodingRequest, RequestKind, MapRegion, AmbiguityResolver, RegionQuery, LevelKind, IgnoringStrategyKind, PayloadKind, ReverseGeocodingRequest
  from .gis.response import Response, SuccessResponse
  from .type_assertion import assert_list_type
label_desc: Use image node_id 1 for calling a global function with example usage: _to_scope(location) and returns: _make_region, None, unknown, MapRegion, MapRegion