Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Koos Zevenhoven
On Fri, May 13, 2016 at 8:52 PM, Steven D'Aprano wrote: > On Fri, May 13, 2016 at 03:43:29PM +, Brett Cannon wrote: >> On Fri, 13 May 2016 at 04:00 Steven D'Aprano wrote: > > [...] >> > I think it is a bit confusing to refer to "path objects", as that seems >> > like you are referring only to

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Brett Cannon
On Fri, 13 May 2016 at 10:53 Steven D'Aprano wrote: > On Fri, May 13, 2016 at 03:43:29PM +, Brett Cannon wrote: > > On Fri, 13 May 2016 at 04:00 Steven D'Aprano > wrote: > > [...] > > > - but os.fspath() will only return str; > > > - and os.fspathb() will only return bytes; > > > I prefer wh

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Steven D'Aprano
On Fri, May 13, 2016 at 03:43:29PM +, Brett Cannon wrote: > On Fri, 13 May 2016 at 04:00 Steven D'Aprano wrote: [...] > > - but os.fspath() will only return str; > > - and os.fspathb() will only return bytes; > I prefer what's in the PEP. I get where you coming from, Steven, but I > don't th

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Guido van Rossum
On Fri, May 13, 2016 at 9:34 AM, Ethan Furman wrote: > I would say use `type(x).__fspath__`. I'm not aware of any other > __dunder__ method that doesn't access the attribute from the type instead > of the instance, and I see no point in making this one different. > Agreed. -- --Guido van Ross

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Guido van Rossum
On Fri, May 13, 2016 at 9:33 AM, Larry Hastings wrote: > > > On 05/13/2016 06:21 PM, Guido van Rossum wrote: > > Really, if you want bytes, you should use os.fsencode(); if you want > strings, use os.fsencode(); if you want to be polymorphic, use os.fspath() > and check the type it returns. > > >

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Chris Angelico
On Sat, May 14, 2016 at 2:34 AM, Ethan Furman wrote: > I would say use `type(x).__fspath__`. I'm not aware of any other __dunder__ > method that doesn't access the attribute from the type instead of the > instance, and I see no point in making this one different. > __reduce__ / __reduce_ex__ in

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Larry Hastings
On 05/13/2016 06:21 PM, Guido van Rossum wrote: Really, if you want bytes, you should use os.fsencode(); if you want strings, use os.fsencode(); if you want to be polymorphic, use os.fspath() and check the type it returns. Am I severely misunderstanding the API, or did you mean "if you want

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Ethan Furman
On 05/13/2016 08:43 AM, Brett Cannon wrote: a minor technical query: try: return path.__fspath__() Would I be right in saying that in practice this will actually end up being type(path).__fspath__() to match the behaviour of all(?) other dunder methods? I wasn't planning

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Koos Zevenhoven
On Fri, May 13, 2016 at 2:00 PM, Steven D'Aprano wrote: > Counter suggestion: > > - __fspath__() method may return either bytes or str (no change > from the PEP as it stands now); > > - but os.fspath() will only return str; > > - and os.fspathb() will only return bytes; > > - there is no os func

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Guido van Rossum
On Fri, May 13, 2016 at 4:00 AM, Steven D'Aprano wrote: > On Thu, May 12, 2016 at 08:53:12PM +, Brett Cannon wrote: > > > Second draft that takes Guido's comments into consideration. The biggest > > change is os.fspath() now returns whatever path.__fspath__() returns > > instead of restrictin

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Brett Cannon
On Fri, 13 May 2016 at 04:00 Steven D'Aprano wrote: > On Thu, May 12, 2016 at 08:53:12PM +, Brett Cannon wrote: > > > Second draft that takes Guido's comments into consideration. The biggest > > change is os.fspath() now returns whatever path.__fspath__() returns > > instead of restricting it

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Random832
On Fri, May 13, 2016, at 07:00, Steven D'Aprano wrote: > - but os.fspath() will only return str; > > - and os.fspathb() will only return bytes; And raise an exception if __fspath__ returns the other, I suppose. What's the use case for these functions? When would I call them rather than fsdecode a

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Joseph Martinot-Lagarde
> - there is no os function that returns "str or bytes, I don't > care which". (If you really need that, call __fspath__ directly.) os.fspath() in the PEP works when given str or bytes directly, but those don't have a __fspath__ method, so directly calling the dunder method is not equivalent to

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Koos Zevenhoven
Thanks Brett! Now one thing is that, despite your suggestion, I had not added myself as an author in my big pull request. Originally, it was because I simply forgot to copy and paste it when I split my edits into separate commits ;-). Sorry about that (not sure if you care though, and I've been de

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Nick Coghlan
On 13 May 2016 at 21:00, Steven D'Aprano wrote: > On Thu, May 12, 2016 at 08:53:12PM +, Brett Cannon wrote: > >> Second draft that takes Guido's comments into consideration. The biggest >> change is os.fspath() now returns whatever path.__fspath__() returns >> instead of restricting it to only

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Chris Angelico
On Fri, May 13, 2016 at 9:00 PM, Steven D'Aprano wrote: > Cons: > (3) Polymorphic code that truly doesn't care whether it gets bytes or > str will have a slightly less convenient way of getting it, namely by > calling __fspath__() itself, instead of os.fspath(). I don't like this; it goes against

Re: [Python-Dev] File system path PEP, part 2

2016-05-13 Thread Steven D'Aprano
On Thu, May 12, 2016 at 08:53:12PM +, Brett Cannon wrote: > Second draft that takes Guido's comments into consideration. The biggest > change is os.fspath() now returns whatever path.__fspath__() returns > instead of restricting it to only str. Counter suggestion: - __fspath__() method may r

Re: [Python-Dev] File system path PEP, part 2

2016-05-12 Thread Nick Coghlan
On 13 May 2016 at 06:53, Brett Cannon wrote: > Second draft that takes Guido's comments into consideration. The biggest > change is os.fspath() now returns whatever path.__fspath__() returns instead > of restricting it to only str. > > Minor changes: > - Renamed the C function to PyOS_FSPath() > -