Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Disagreement betweenPureWindowsPath.relative_to() andntpath.relpath() with rootless drives #99029

Closed
@barneygale

Description

@barneygale

On Windows, the pathC: means "the current directory on the C: drive".

But pathlib'srelative_to() treats it as the immediate parent ofC:\. This makes sense lexographically, but it's inconsistent with everything else:

C:\Users\Barney>python>>>importntpath,pathlib>>>ntpath.relpath('C:/Windows','C:/Users/Barney')'..\\..\\Windows'>>>ntpath.relpath('C:/Windows','.')'..\\..\\Windows'>>>ntpath.relpath('C:/Windows','C:')'..\\..\\Windows'>>>pathlib.Path('C:/Windows').relative_to('C:/Users/Barney',walk_up=True)WindowsPath('../../Windows')>>>pathlib.Path('C:/Windows').relative_to('.',walk_up=True)ValueError:Onepathisrelativeandtheotherisabsolute.>>>pathlib.Path('C:/Windows').relative_to('C:')WindowsPath('/Windows')# should be ValueError, as we're mixing absolute + relative paths

This prevents us from usingrelpath() from pathlib, and renders the two implementations incompatible. Booo! Also prevents us from simplifyingis_relative_to() down toother == self or other in self.parents

Special cases aren't special enough to break the rules. Let's make these compatible!

Previous discussion:#84538

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp