Given the variant you [Koos] suggested, what if we defined the API semantics
like this:
# Offer the simplest possible API as the public vesion
def fspath(pathlike) -> str:
return os._raw_fspath(pathlike)
# Expose the complexity in the "private" variant
def _raw_fspath(pathlike, *, output_types = (str,)) -> (str, bytes):
# Short-circuit for instances of the output type
if isinstance(pathlike, output_types):
return pathlike
# We'd have a tidier error message here for non-path objects
result = pathlike.__fspath__()
if not isinstance(result, output_types):
raise TypeError("argument is not and does not provide an
acceptable pathname")
return result