Skip to content

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

Open
@serhiy-storchaka

Description

@serhiy-storchaka

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

Activity

added
type-bugAn unexpected behavior, bug, or error
3.13bugs and security fixes
3.14bugs and security fixes
3.15new features, bugs and security fixes
on Jun 4, 2025
changed the title [-]realpath(..., strict=ALLOW_MISSING) can unexpectedly success on Windows[/-] [+]realpath(..., strict=ALLOW_MISSING) can unexpectedly succeed on Windows[/+] on Jun 4, 2025
encukou

encukou commented on Jun 4, 2025

@encukou
Member

Thanks for the catch! I'd call that a bug (but not a security issue).

serhiy-storchaka

serhiy-storchaka commented on Jun 4, 2025

@serhiy-storchaka
MemberAuthor

At least, such "gotcha" could be documented. I don't know whether we can detect and change this behavior, or leave it as a Windows peculiarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesOS-windowsextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      realpath(..., strict=ALLOW_MISSING) can unexpectedly succeed on Windows · Issue #135122 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant