Skip to content

test(tools): create hard links with os.link for Python 3.9 - #4545

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
thuanquang:test/tools-python39-hard-links
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
thuanquang:test/tools-python39-hard-links

Conversation

@thuanquang

@thuanquang thuanquang commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

import_audit and stubgen error on Python 3.9 before reaching their assertions:

AttributeError: 'PosixPath' object has no attribute 'hardlink_to'

Path.hardlink_to was added in Python 3.10. Python 3.9.6 is the python3 that the Xcode command-line tools install on macOS, which is the toolchain BUILD.md names for the relinker-only build there, and tools/progress.py targets Python 3.9+ (#11). The two tests now create the hard link with os.link(target, link), which does the same on every Python 3 version and on Windows. Only the two test files change.

pr_overlap_encoding also fails on Python 3.9 (subprocess._text_encoding). That is a different cause, and #4361 changes that file, so it is left out here.

Overlap: #4425 also adds import os at the same place in tools/tests/test_import_audit.py. As agreed on #4425, it goes first; I will then rebase this one, keeping a single import os.

Tested

macOS 27 (Apple Silicon), AppleClang 21, relinker-only build of main (d592d54) with -DBUILD_TESTING=ON:

  • Python 3.9.6 (Xcode command-line tools), before: import_audit and stubgen fail with the error above; 121/124 pass.
  • Python 3.9.6, after: import_audit and stubgen pass; 123/124 pass, with pr_overlap_encoding the only failure.
  • Python 3.11.4: test_import_audit.py (37 tests) and test_stubgen.py (11 tests) pass.
  • python3 tools/check_conventions.py --base origin/main passes.

Not tested on Linux or Windows.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: fix(import-audit): preserve JSON reports when writing fails #4425
  • Unblocks: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

Path.hardlink_to was added in Python 3.10, so import_audit and stubgen
errored on Python 3.9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coltken95

Copy link
Copy Markdown

Tested with Python 3.9.25, with 4feeef6 applied onto main 5d50886:

  • On main: test_import_audit and test_stubgen error with
    AttributeError: 'PosixPath' object has no attribute 'hardlink_to'
  • With the PR: all 48 tests in those two files pass.

For reference, tools/tests as a whole (252 tests) still has one failure on 3.9 that this PR doesn't touch:
test_pr_overlap_encoding.EncodingTests.test_default_encoding_uses_simulated_cp1252.
It passes on 3.11 and 3.13.

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test: head 4feeef698 merged onto current main 0f2683cb7, together with 5 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest for the tests this change adds or touches: import_audit passed, stubgen passed; python tools/check_conventions.py --base upstream/main passed for the combined tree. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked: os.link(target, link) is equivalent to hardlink_to on every Python 3 version; test_stubgen.py already imports os. Merged on current main, scoped build and ctest pass (29/29). Python 3.9 results confirmed by @coltken95 (Linux 3.9.25) and Windows by @xXPBSXx; merging.

@adriadam10
adriadam10 merged commit c02df17 into boykopovar:main Oct 13, 2026
10 checks passed
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.

4 participants