[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for fspath and os.fspath() (original) (raw)
Fred Drake fred at fdrake.net
Wed Apr 13 12🔞36 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 Wed, Apr 13, 2016 at 11:09 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
- a single os.fspath() with an allowbytes parameter (mostly True in os and os.path, mostly False everywhere else)
-0
- a str-only os.fspathname() and a str/bytes os.fspath()
+1 on using separate functions.
I'm partial to the first choice as it is simplicity itself to know when looking at it if bytes might be coming back by the presence or absence of a second argument to the call; otherwise one has to keep straight in one's head which is str-only and which might allow bytes (I'm not very good at keeping similar sounding functions separate -- what's the difference between shutil.copy and shutil.copy2? I have to look it up every time).
I do the same, but... this is one of those cases where a caller will usually be passing a constant directly. If passed as a positional argument, it'll just be confusing ("what's True?" is my usual reaction to a Boolean positional argument). If passed as a keyword argument with a descriptive name, it'll be longer than I'd like to see:
path_str = os.fspath(path, allow_bytes=True)
Names like os.fspath() and os.fssyspath() seem good to me.
-Fred
-- Fred L. Drake, Jr. "A storm broke loose in my mind." --Albert Einstein
- 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 ]