Skip to content

fix(posixpath): realpath(strict=False) joins a missing tail lexically (#714) - #723

Merged
espetro merged 2 commits into
masterfrom
work/714
Oct 27, 2026
Merged

espetro merged 2 commits into
masterfrom
work/714

Conversation

@espetro

@espetro espetro commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

What

ps_path_realpath previously raised whenever realpath(3) failed. CPython's
os.path.realpath defaults to strict=False: it resolves symlinks on the
existing leading components and, when the target is missing, joins the
remaining tail lexically (mirroring posixpath._joinrealpath).

The rewrite keeps the fast path when realpath(3) succeeds and otherwise
shrinks to the longest prefix realpath() can resolve, then joins the rest
verbatim through ps_path_join — so os.path.basename(os.path.realpath('a/../b')) == 'b'
traces correctly (abs → normpath → missing leaf → join → basename 'b').

The differential sweep's REALPATH_DIVERGENCE reference and the probe's
divergence= kwarg are removed, so the paths batch now passes on its own.

Stacking

This PR is stacked on #713 (which is stacked on #712 on #715). Merge order:
#715 → #712 → #713 → this PR.

Testing

  • tests/test_stdlib_call_table.py — the realpath probe now expects the
    CPython strict=False result (no divergence reference).
  • Local gcc -fsyntax-only -Wall check of ps_path.c against the runtime
    header contract passes.

Closes #714

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Deploying pyscriptc with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3ba8d64
Status:🚫  Build failed.

View logs

@espetro espetro added this to the v0.7.0 milestone Oct 27, 2026
@espetro
espetro changed the base branch from work/713 to master October 27, 2026 08:26
espetro and others added 2 commits October 27, 2026 01:51
…#714)

ps_path_realpath used to raise whenever realpath(3) failed, while CPython's
default strict=False resolves the existing leading components and joins the
rest of the path lexically. Shrink to the longest prefix realpath() accepts
and join the remainder verbatim, so os.path.realpath('a/../b') on a missing
target no longer diverges from CPython 3.14.

Closes #714
@espetro
espetro merged commit c5fd936 into master Oct 27, 2026
34 of 35 checks passed
@espetro
espetro deleted the work/714 branch October 27, 2026 21:41
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.

fix(posixpath): realpath raises on a missing target where CPython returns a path

1 participant