[Python-ideas] PEP 428 - joining

MRAB python at mrabarnett.plus.com
Mon Oct 8 00:29:25 CEST 2012


On 2012-10-07 23:11, Georg Brandl wrote:
> Am 07.10.2012 23:42, schrieb Antoine Pitrou:
>> 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.
>
> Please no -- this is a very important use case (for os.path.join, at least):
> resolving a path from config/user/command line that can be given either absolute
> or relative to a certain directory.
>
> Right now it's as simple as join(default, path), and i'd prefer to keep this.
> There is no bug here, it's working as designed.
>
In that use case, wouldn't it be more likely that the default is itself
absolute, so it'd be either relative to that absolute path or
overriding that absolute path with another absolute path?



More information about the Python-ideas mailing list