Skip to content

gh-71189: Support all-but-last mode in os.path.realpath() #117562

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

Merged
merged 19 commits into from
Jul 30, 2025

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 5, 2024

@serhiy-storchaka serhiy-storchaka changed the title gh-71189: Support all-but-last mode in posixpath.realpath() gh-71189: Support all-but-last mode in os.path.realpath() May 20, 2025
@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review May 20, 2025 09:48
@serhiy-storchaka
Copy link
Member Author

The original patch was created in 2016, but it has been rewritten from scratch several times as the realpath() code has changed several times over the years. The Windows implementation was created only now.

@serhiy-storchaka serhiy-storchaka marked this pull request as draft May 20, 2025 13:26
@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review May 20, 2025 14:19
Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change seems fine to me. I have no opinion on whether it's worth adding the functionality (calling realpath(dirname(p)) seems like a sufficient approach in any case that's useful - if I might need the real filename then I probably need to know whether it's real or not, so this option doesn't help me).

serhiy-storchaka and others added 2 commits July 29, 2025 21:33
@serhiy-storchaka
Copy link
Member Author

This is not so simple. The last component may be a link which refers to a path in which only the last component does not exist. For example:

$ ln -s dir/sub/file link
$ realpath link
realpath: link: No such file or directory
$ mkdir dir
$ realpath link
realpath: link: No such file or directory
$ mkdir dir/sub
$ realpath link
/tmp/dir/sub/file

This is also the default mode of realpath, as it is the most useful.

@zooba
Copy link
Member

zooba commented Jul 29, 2025

Oh okay, so it's only for the case where the last segment is a link but the last segment of the target doesn't exist?

In your example above, what would realpath dir/sub/file show? Does it resolve dir/sub and then assume /file? Or does it fail because file doesn't exist?

@serhiy-storchaka
Copy link
Member Author

It shows dir/sub/file if dir/sub exists and is a directory. It fails if dir or dir/sub doe not exist or are not directories.

This is yet one difference from resolving the parent -- it must also be a directory.

@zooba
Copy link
Member

zooba commented Jul 29, 2025

Makes sense. Still can't think of what I'd use it for, but being able to easily match a POSIX tool's defaults seems reasonable enough.

@serhiy-storchaka serhiy-storchaka merged commit 9d3b53c into python:main Jul 30, 2025
41 checks passed
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86-64 MacOS Intel NoGIL 3.x (tier-1) has failed when building commit 9d3b53c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1258/builds/5560) and take a look at the build logs.
  4. Check if the failure is related to this commit (9d3b53c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1258/builds/5560

Failed tests:

  • test_subprocess

Failed subtests:

  • test_leak_fast_process_del_killed - test.test_subprocess.POSIXProcessTestCase.test_leak_fast_process_del_killed

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-intel-aws.nogil/build/Lib/test/test_subprocess.py", line 3195, in test_leak_fast_process_del_killed
    self.assertRaises(OSError, os.waitpid, pid, 0)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: OSError not raised by waitpid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy