[Python-ideas] PEP 428 - joining

Antoine Pitrou solipsis at pitrou.net
Sun Oct 7 23:42:12 CEST 2012


On Sun, 7 Oct 2012 23:15:38 +0200
Yuval Greenfield <ubershmekel at gmail.com>
wrote:
> On Sun, Oct 7, 2012 at 7:37 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> 
> > On Sat, 6 Oct 2012 10:44:37 -0700
> > Guido van Rossum <guido at python.org> wrote:
> > >
> > > But rather than diving right into the syntax, I would like to focus on
> > > some use cases. (Some of this may already be in the PEP, my
> > > apologize.) Some things I care about (based on path manipulations I
> > > remember I've written at some point or another):
> > >
> > > - Distinguishing absolute paths from relative paths; this affects
> > > joining behavior as for os.path.join().
> >
> > The proposed API does function like os.path.join() in that respect:
> > when joining a relative path to an absolute path, the relative path is
> > simply discarded:
> >
> > >>> p = PurePath('a')
> > >>> q = PurePath('/b')
> > >>> p[q]
> > PurePosixPath('/b')
> >
> >
> What's the use case for this behavior?
> 
> I'd much rather if joining an absolute path to a relative one fail and
> reveal the potential bug....
> 
>     >>> os.unlink(Path('myproj') / Path('/lib'))
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     TypeError: absolute path can't be appended to a relative path

In all honesty I followed os.path.join's behaviour here. I agree a
ValueError (not TypeError) would be sensible too.

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net





More information about the Python-ideas mailing list