1. Antoine Pitrou
  2. pathlib
  3. Issues
Issue #14 invalid

Abspath doesn't cut ".." from path name.

Konstantine Rybnikov
created an issue

When you call os.abspath, it removes unneeded ".." from your path, so if you were in '/a/b/c' and you called os.abspath('/a/b/c/../'), you'd get '/a/b/'.

I think .absolute() on PosixPath should get the same behavior.

Comments (3)

  1. July Tikhonov

    The description of Path.absolute() method states that "This function works even if the path doesn't point to anything". So, this method must be purely lexical (except for using cwd). This means that it cannot resolve any '..' parts, because this can change the meaning of the path (in case of symbolic links presence). To correctly resolve '..' parts, you should use Path.resolve() method.

  2. Antoine Pitrou repo owner

    Thanks July. July is right, resolve() is the only method which will collapse ".." components. The reason is simple: if /tmp is a symlink to /var/tmp, then /tmp/../usr is not the same as /usr !

  3. Log in to comment