python / python/cpython

realpath(..., strict=ALLOW_MISSING) can unexpectedly succeed on Windows

Open
#135,122 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.13 3.14 3.15 extension-modules OS-windows type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

In new tests added for #117562 I noticed that os.path.realpath('file1/file2', strict=os.path.ALLOW_MISSING) returns 'file1/file2' when file file1 exist on Windows.

On Posix you will get NotADirectoryError here, but Windows raises ALLOW_MISSING if the intermediate path is a file instead of directory, and it will be ignored with ALLOW_MISSING.

It is expected that if realpath(..., strict=ALLOW_MISSING) does not fail, you can simply create intermediate directories or the final file/directory. At least on Posix. But on Windows it will always fail, because there is already a file here.

cc @encukou

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Windows behavior of os.path.realpath('file1/file2', strict=os.path.ALLOW_MISSING) described in the report, then compare it with the new tests from #117562 and the corresponding POSIX result. Done means an existing intermediate file is not treated as a valid missing path and the relevant Windows tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.