def METHOD_NAME(self, path, location=None, mapset=None):
    """Switch to a mapset provided as a name or path.
    The mapset can be provided as a name, as a path,
    or as database, location, and mapset.
    Specifically, the *path* positional-only parameter can be either
    name of a mapset in the current location or a full path to a mapset.
    When location and mapset are provided using the additional parameters,
    the *path* parameter is path to a database.
    Raises ValueError if the mapset does not exist (e.g., when the name is
    misspelled or the mapset is invalid).
    """
    # The method could be a function, but this is more general (would work even for
    # a non-global session).
    # pylint: disable=no-self-use
    # Functions needed only here.
    # pylint: disable=import-outside-toplevel
    from grass.grassdb.checks import (
        get_mapset_invalid_reason,
        is_mapset_valid,
        mapset_exists,
    )
    from grass.grassdb.manage import resolve_mapset_path
    # For only one parameter, try if it is a mapset in the current location to
    # support switching only by its name.
    gisenv = gs.gisenv()
    if (
        not location
        and not mapset
        and mapset_exists(
            path=gisenv["GISDBASE"], location=gisenv["LOCATION_NAME"], mapset=path
        )
    ):
        gs.run_command("g.gisenv", set=f"MAPSET={path}")
        return
    mapset_path = resolve_mapset_path(path=path, location=location, mapset=mapset)
    if not is_mapset_valid(mapset_path):
        raise ValueError(
            _("Mapset {path} is not valid: {reason}").format(
                path=mapset_path.path,
                reason=get_mapset_invalid_reason(
                    mapset_path.directory, mapset_path.location, mapset_path.mapset
                ),
            )
        )
    # This requires direct session file modification using g.gisenv because
    # g.mapset locks the mapset which is not how init and finish behave.
    # For code simplicity, we just change all even when only mapset is changed.
    gs.run_command("g.gisenv", set=f"GISDBASE={mapset_path.directory}")
    gs.run_command("g.gisenv", set=f"LOCATION_NAME={mapset_path.location}")
    gs.run_command("g.gisenv", set=f"MAPSET={mapset_path.mapset}")