Skip to content

os.path.relpath() assumes '//' root is equivalent to '/' #92737

@iynehz

Description

@iynehz

Bug report

pathlib's Path.relative_to() and os.path.relpath(), the two have different behavior: On Linux os.path.relpath() understands double-slash in path is same as single slash, but Path.relative_to() does not.

For example,

import os
os.path.relpath('//foo/bar', '/foo')                 # results 'bar'

from pathlib import Path
pathlib.PosixPath('//foo/bar').relative_to('/foo')   # raises ValueError

pytest issue pytest-dev/pytest#9894 relates to this.

Your environment

  • CPython versions tested on: 3.9.2
  • Operating system and architecture: Debian Bullseye

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions