(path)
return display_path
Convert a bytes (or text) path to text (unicode in Python 2) for display
    and logging purposes.

    This function should never error out. Also, this function is mainly needed
    for Python 2 since in Python 3 str paths are already text.
Convert a bytes (or text) path to text (unicode in Python 2) for display
    and logging purposes.
Convert a bytes ( or text ) path to text ( unicode in Python 2 ) for display and logging purposes .
def path_to_display(path):
    # type: (Optional[Union[str, Text]]) -> Optional[Text]
    """
    Convert a bytes (or text) path to text (unicode in Python 2) for display
    and logging purposes.

    This function should never error out. Also, this function is mainly needed
    for Python 2 since in Python 3 str paths are already text.
    """
    if path is None:
        return None
    if isinstance(path, text_type):
        return path
    # Otherwise, path is a bytes object (str in Python 2).
    try:
        display_path = path.decode(sys.getfilesystemencoding(), 'strict')
    except UnicodeDecodeError:
        # Include the full bytes to make troubleshooting easier, even though
        # it may not be very human readable.
        if PY2:
            # Convert the bytes to a readable str representation using
            # repr(), and then convert the str to unicode.
            #   Also, we add the prefix "b" to the repr() return value both
            # to make the Python 2 output look like the Python 3 output, and
            # to signal to the user that this is a bytes representation.
            display_path = str_to_display('b{!r}'.format(path))
        else:
            # Silence the "F821 undefined name 'ascii'" flake8 error since
            # in Python 3 ascii() is a built-in.
            display_path = ascii(path)  # noqa: F821

    return display_path
def path_to_display ( path ) : # type: (Optional[Union[str, Text]]) -> Optional[Text] if path is None : return None if isinstance ( path , text_type ) : return path # Otherwise, path is a bytes object (str in Python 2). try : display_path = path . decode ( sys . getfilesystemencoding ( ) , 'strict' ) except UnicodeDecodeError : # Include the full bytes to make troubleshooting easier, even though # it may not be very human readable. if PY2 : # Convert the bytes to a readable str representation using # repr(), and then convert the str to unicode. #   Also, we add the prefix "b" to the repr() return value both # to make the Python 2 output look like the Python 3 output, and # to signal to the user that this is a bytes representation. display_path = str_to_display ( 'b{!r}' . format ( path ) ) else : # Silence the "F821 undefined name 'ascii'" flake8 error since # in Python 3 ascii() is a built-in. display_path = ascii ( path ) # noqa: F821 return display_path