from typing import AnyStr
import locale


def to_string(path: AnyStr) -> str:
    """Return the string representation of a byte string using the preferred
     encoding, or the string itself if path is a str."""
    if isinstance(path, bytes):
        return path.decode(locale.getpreferredencoding(False))
    return path