Re: [Python-ideas] tweaking the file system path protocol

2017-05-29 Thread Wolfgang Maier
On 05/29/2017 09:55 AM, Serhiy Storchaka wrote: 29.05.17 00:33, Wolfgang Maier пише: The path protocol does *not* use __fspath__ as an indicator that an object's str-representation is intended to be used as a path. If you had wanted this, the PEP should have defined __fspath__ not as a

Re: [Python-ideas] tweaking the file system path protocol

2017-05-29 Thread Serhiy Storchaka
29.05.17 00:33, Wolfgang Maier пише: The path protocol does *not* use __fspath__ as an indicator that an object's str-representation is intended to be used as a path. If you had wanted this, the PEP should have defined __fspath__ not as a method, but as a flag and have the protocol check that

Re: [Python-ideas] tweaking the file system path protocol

2017-05-28 Thread Juancarlo Añez
On Sun, May 28, 2017 at 5:33 PM, Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > With __fspath__ being a method that can return whatever its author sees > fit, calling str to get a path from an arbitrary object is just as wrong as > it always was - it will work for pathlib.Path

Re: [Python-ideas] tweaking the file system path protocol

2017-05-28 Thread Wolfgang Maier
On 28.05.2017 18:32, Steven D'Aprano wrote: On Sun, May 28, 2017 at 05:35:38PM +0300, Koos Zevenhoven wrote: Don't get me wrong, I like consistency very much. But regarding the __fspath__ case, there are not that many people *writing* fspath-enabled classes. Instead, there are many many many

Re: [Python-ideas] tweaking the file system path protocol

2017-05-28 Thread Koos Zevenhoven
On Sun, May 28, 2017 at 9:15 AM, Nick Coghlan wrote: > > However, if we *did* make such a change, it should also be made for > operator.index as well, since that is similarly inconsistent with the > way the int/float/etc constructor protocols work: > Part of this discussion

Re: [Python-ideas] tweaking the file system path protocol

2017-05-28 Thread Nick Coghlan
On 28 May 2017 at 15:18, Steven D'Aprano wrote: > On Fri, May 26, 2017 at 03:58:23PM +0300, Koos Zevenhoven wrote: > I think this argument about backwards compatibility is a storm in a tea > cup. We can enumerate all the possibilities: > > 1. object that doesn't inherit from

Re: [Python-ideas] tweaking the file system path protocol

2017-05-27 Thread Steven D'Aprano
On Fri, May 26, 2017 at 03:58:23PM +0300, Koos Zevenhoven wrote: > On Wed, May 24, 2017 at 5:52 PM, Wolfgang Maier > wrote: > > On 05/24/2017 02:41 AM, Steven D'Aprano wrote: [...] > > This is almost exactly what I have been thinking (just that I

Re: [Python-ideas] tweaking the file system path protocol

2017-05-26 Thread Koos Zevenhoven
On Wed, May 24, 2017 at 5:52 PM, Wolfgang Maier wrote: > On 05/24/2017 02:41 AM, Steven D'Aprano wrote: >> >> >> It would be annoying and inconsistent if int(x) avoided calling __int__ >> on int subclasses. But that's exactly what happens with fspath and

Re: [Python-ideas] tweaking the file system path protocol

2017-05-26 Thread Koos Zevenhoven
On Wed, May 24, 2017 at 3:41 AM, Steven D'Aprano wrote: > On Wed, May 24, 2017 at 12:18:16AM +0300, Serhiy Storchaka wrote: >> I don't know a reasonable use case for this feature. The __fspath__ >> method of str or bytes subclasses returning something not equivalent to >>

Re: [Python-ideas] tweaking the file system path protocol

2017-05-24 Thread Wolfgang Maier
On 05/24/2017 02:41 AM, Steven D'Aprano wrote: On Wed, May 24, 2017 at 12:18:16AM +0300, Serhiy Storchaka wrote: It seems to me that the purpose of this proposition is not performance, but the possibility to use __fspath__ in str or bytes subclasses. Currently defining __fspath__ in str or

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Steven D'Aprano
On Wed, May 24, 2017 at 12:18:16AM +0300, Serhiy Storchaka wrote: > 23.05.17 20:04, Brett Cannon пише: > >What exactly is the performance issue you are having that is leading to > >this proposal? > > It seems to me that the purpose of this proposition is not performance, > but the possibility

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread tritium-list
s@python.org> > Subject: Re: [Python-ideas] tweaking the file system path protocol > > On Wed, May 24, 2017 at 12:18 AM, Serhiy Storchaka > <storch...@gmail.com> wrote: > > It seems to me that the purpose of this proposition is not performance, but > > the possibi

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Koos Zevenhoven
On Wed, May 24, 2017 at 12:18 AM, Serhiy Storchaka wrote: > It seems to me that the purpose of this proposition is not performance, but > the possibility to use __fspath__ in str or bytes subclasses. Currently > defining __fspath__ in str or bytes subclasses doesn't have any

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Serhiy Storchaka
23.05.17 20:04, Brett Cannon пише: On Tue, 23 May 2017 at 03:13 Wolfgang Maier > wrote: My proposal is to change this to: 1) check whether the type of the argument is str or bytes *exactly*; if

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Koos Zevenhoven
On Tue, May 23, 2017 at 7:53 PM, Wolfgang Maier wrote: > > Ah, sorry, I misunderstood what you were trying to say, but now I'm getting > it! subclasses of str and bytes were of course usable as path arguments > before simply because they were subclasses of

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Guido van Rossum
I see no future for this proposal. Sorry Wolfgang! For future reference, the proposal was especially weak because it gave no concrete examples of code that was inconvenienced in any way by the current behavior. (And the performance hack of checking for exact str/bytes can be made without changing

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Brett Cannon
On Tue, 23 May 2017 at 03:13 Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > What do you think of this idea for a slight modification to os.fspath: > the current version checks whether its arg is an instance of str, bytes > or any subclass and, if so, returns the arg unchanged.

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Wolfgang Maier
On 05/23/2017 06:17 PM, Koos Zevenhoven wrote: On Tue, May 23, 2017 at 1:12 PM, Wolfgang Maier wrote: What do you think of this idea for a slight modification to os.fspath: the current version checks whether its arg is an instance of str, bytes or any

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Wolfgang Maier
On 05/23/2017 06:41 PM, Wolfgang Maier wrote: On 05/23/2017 06:17 PM, Koos Zevenhoven wrote: On Tue, May 23, 2017 at 1:12 PM, Wolfgang Maier wrote: What do you think of this idea for a slight modification to os.fspath: the current version checks

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Koos Zevenhoven
On Tue, May 23, 2017 at 1:49 PM, Steven D'Aprano wrote: > > How about simplifying the implementation of fspath by giving str and > bytes a __fspath__ method that returns str(self) or bytes(self)? > The compatiblity issue I mention in the other email I just sent as a response

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Koos Zevenhoven
On Tue, May 23, 2017 at 1:12 PM, Wolfgang Maier wrote: > What do you think of this idea for a slight modification to os.fspath: > the current version checks whether its arg is an instance of str, bytes or > any subclass and, if so, returns the arg

Re: [Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Steven D'Aprano
On Tue, May 23, 2017 at 12:12:11PM +0200, Wolfgang Maier wrote: > Here's how the proposal could be implemented in the pure Python version > (os._fspath): > > def _fspath(path): > path_type = type(path) > if path_type is str or path_type is bytes: > return path How about

[Python-ideas] tweaking the file system path protocol

2017-05-23 Thread Wolfgang Maier
What do you think of this idea for a slight modification to os.fspath: the current version checks whether its arg is an instance of str, bytes or any subclass and, if so, returns the arg unchanged. In all other cases it tries to call the type's __fspath__ method to see if it can get str,