[Python-ideas] PEP 428 - object-oriented filesystem paths

Yuval Greenfield ubershmekel at gmail.com
Sun Oct 7 23:15:38 CEST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121007/b7724e6a/attachment.html>


More information about the Python-ideas mailing list