[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for fspath and os.fspath() (original) (raw)
Ethan Furman ethan at stoneleaf.us
Mon Apr 18 10:03:28 EDT 2016
- Previous message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Next message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 04/18/2016 12:41 AM, Nick Coghlan wrote:
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.rawfspath(pathlike) # Expose the complexity in the "private" variant def rawfspath(pathlike, *, outputtypes = (str,)) -> (str, bytes): # Short-circuit for instances of the output type if isinstance(pathlike, outputtypes): return pathlike # We'd have a tidier error message here for non-path objects result = pathlike.fspath() if not isinstance(result, outputtypes): raise TypeError("argument is not and does not provide an acceptable pathname") return result
My initial reaction was that this was overly complex, but after thinking about it a couple days I /really/ like it. It has a reasonable default for the 99% real-world use-case, while still allowing for custom and exact tailoring (for the 99% stdlib use-case ;) .
--
Ethan
- Previous message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Next message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]