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

Ethan Furman ethan at stoneleaf.us
Thu Apr 14 21:01:00 EDT 2016


On 04/14/2016 05:20 PM, Stephen J. Turnbull wrote:

However, the proposed polymorphism does create ambiguity and risk for my uses. I rarely have the luxury of not ensuring paths are text, regardless of the bytes-ness of the underlying application, because I can be pretty darn sure that somebody's going to feed me non- filesystem encodings, and soon. Even when I am working with bytes representing paths in the filesystem encoding, I need to convert to text to read the darn things when debugging! So I don't consent; you'll have to impose it on me.

Hmm. Well, the good news is you have convinced me that letting bytes through willy-nilly is akin to loosing the hounds of hell on our code. The bad news is I was never in that camp. ;)

The camp I'm in is a function* that, be default, will raise if bytes enters the picture -- but will allow them through if the user specifically says they are okay with getting bytes.

Would that work for you?

-- Ethan

*Or pair of functions, one that is str-only, one that allows both -- but I'd rather just have one function with a flag.



More information about the Python-Dev mailing list