[issue23082] pathlib relative_to() can give confusing error message

Chris Jerdonek report at bugs.python.org
Thu Dec 18 14:37:19 CET 2014


New submission from Chris Jerdonek:

pathlib's relative_to(other) can give a confusing message when "other" is os.curdir.

For example--

    Python 3.4.2 (default, Nov 12 2014, 18:23:59) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> from pathlib import Path
    >>> Path("/foo").relative_to(os.curdir)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 806, in relative_to
        .format(str(self), str(formatted)))
    ValueError: '/foo' does not start with ''

I guess the error here is that the path must be relative when "other" is relative.

----------
components: Library (Lib)
messages: 232876
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: pathlib relative_to() can give confusing error message
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23082>
_______________________________________


More information about the Python-bugs-list mailing list