Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output relative path when using PurePath.relative_to #88244

Closed
mhammondr mannequin opened this issue May 8, 2021 · 2 comments
Closed

Output relative path when using PurePath.relative_to #88244

mhammondr mannequin opened this issue May 8, 2021 · 2 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mhammondr
Copy link
Mannequin

mhammondr mannequin commented May 8, 2021

BPO 44078
Nosy @akulakov
Superseder
  • bpo-40358: pathlib's relative_to should behave like os.path.relpath
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-05-14.22:17:49.000>
    created_at = <Date 2021-05-08.15:43:11.323>
    labels = ['type-feature', 'library', '3.9']
    title = 'Output relative path when using PurePath.relative_to'
    updated_at = <Date 2022-02-22.23:52:20.218>
    user = 'https://bugs.python.org/mhammondr'

    bugs.python.org fields:

    activity = <Date 2022-02-22.23:52:20.218>
    actor = 'Socob'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-14.22:17:49.000>
    closer = 'terry.reedy'
    components = ['Library (Lib)']
    creation = <Date 2021-05-08.15:43:11.323>
    creator = 'mhammondr'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44078
    keywords = []
    message_count = 2.0
    messages = ['393262', '393286']
    nosy_count = 3.0
    nosy_names = ['Socob', 'andrei.avk', 'mhammondr']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '40358'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44078'
    versions = ['Python 3.9']

    @mhammondr
    Copy link
    Mannequin Author

    mhammondr mannequin commented May 8, 2021

    Comparing two paths, PurePath.relative_to fails with ValueError if the second path is not in the first.

    >>> Path('/a/b').relative_to('/a/b/c')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.9/pathlib.py", line 928, in relative_to
        raise ValueError("{!r} is not in the subpath of {!r}"
    ValueError: '/a/b' is not in the subpath of '/a/b/c' OR one path is relative and the other is absolute.

    Please extend PurePath.relative_to so it is able to output a relative path in form of '..' instead of an error. Currently, the only way to do this is to use relpath from os.path but it would be very useful if Path was able to output the relative path.

    @mhammondr mhammondr mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 8, 2021
    @akulakov
    Copy link
    Contributor

    akulakov commented May 8, 2021

    duplicate of https://bugs.python.org/issue40358 , which has an open patch.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants