[Python-ideas] PEP 428: poll about the joining syntax

Joshua Landau joshua.landau.ws at gmail.com
Fri Oct 12 22:45:58 CEST 2012


On 12 October 2012 20:39, Georg Brandl <g.brandl at gmx.net> wrote:

> Am 12.10.2012 18:27, schrieb Ethan Furman:
> > Georg Brandl wrote:
> >> Am 12.10.2012 14:45, schrieb Blake Hyde:
> >>> I'm a Python developer rather than a developer of Python, but I'd like
> to ask a
> >>> question about this option (and implicitly vote against it, I
> suppose); if you
> >>> specialize a method name, such as .pathjoin, aren't you implying that
> methods
> >>> must be unambiguous even across types and classes?  This seems
> negative.  Even
> >>> if .join is already used for strings, it also makes sense for this use
> case.
> >>
> >> Of course different classes can have methods of the same name.
> >>
> >> The issue here is that due to the similarity (and interchangeability)
> of path
> >> objects and strings it is likely that people get them mixed up every
> now and
> >> then, and if .join() works on both objects the failure mode (strange
> result
> >> from str.join when you expected path.join) is horribly confusing.
> >
> > I don't understand the "horribly confusing" part.  Sure, when I got them
> > mixed up and ended up with a plain ol' string instead of a really cool
> > Path it took a moment to figure out where I had made the error, but the
> > traceback of "AttributeError: 'str' object has no attribute 'path'" left
> > absolutely no room for confusion as to what the problem was.
>
> "no attribute 'path'"?  Not sure where that exception comes from.
> This is what I meant:
>
> >>> p = Path('/usr')
> >>> p.join('lib')
> Path('/usr/lib')
>
> >>> p = '/usr'
> >>> p.join('lib')
> 'l/usri/usrb'
>

I don't know about you, but I found that so horribly confusing I had to
check the output. I'm just not used to thinking of str.join(str) as
sensible, and I could not for the life of me see where the
output 'l/usri/usrb' came from. Where was "lib"?

I might just have been an idiot for a minute, but it'll just get harder in
real code. And I'm not the worst for stupid mistakes: we wan't newbies to
be able (and want) to use the built in path modules. When they come back
wondering why

> homepath.join("joshua").join(".config")

returned
>
>
> '.j/homeo/homes/homeh/homeu/homeacj/homeo/homes/homeh/homeu/homeaoj/homeo/homes/homeh/homeu/homeanj/homeo/homes/homeh/homeu/homeafj/homeo/homes/homeh/homeu/homeaij/homeo/homes/homeh/homeu/homeag'

we are going to have a problem.

So I agree with you [Georg Brandl] here. I would even rather
.pathjoin/.joinpath than .join despite the utterly painful name*.

* As others have stated, if you like it why not .strjoin and .dictupdate
and .listappend?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121012/b8968026/attachment.html>


More information about the Python-ideas mailing list