[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Apr 11 20:55:43 EDT 2016


Ethan Furman wrote:
>   # after new protocol with bytes/str support
>   def zingar(a_path):
>       a_path = fspath(a_path)
>       if not isinstance(a_path, (bytes,str)):
>           raise TypeError('bytes or str required')
>       ...

I think that one would be just

    def zingar(a_path):
        a_path = fspath(a_path)

because fspath() would presumably check the result for
str/bytesness itself. At least I can't think of a reason
for it not to, since returning either str or bytes is
part of its contract.

-- 
Greg


More information about the Python-Dev mailing list