[STUBGEN] Let a file declare a namespace with a prefix directive - #752
Open
Seven-Streams wants to merge 4 commits into
Open
[STUBGEN] Let a file declare a namespace with a prefix directive#752Seven-Streams wants to merge 4 commits into
prefix directive#752Seven-Streams wants to merge 4 commits into
Conversation
Seven-Streams
force-pushed
the
main-dev/2026-09-05/stubgen_prefix
branch
from
September 6, 2026 02:50
1a0a02d to
9ee41f1
Compare
prefix directive
Seven-Streams
marked this pull request as ready for review
September 6, 2026 03:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A file that starts with
owns every object registered directly under
tirx(tirx.transform.*is another file). On each run the tool appends an emptyobject/<key>block for every such object that no file of the run defines yet, parents first, after the file's last block, and fills it as usual; animport-sectionis added after theprefixline when the file has none.skipleaves one object out, and a skipped object counts as not asked for, so the dependency error from #748 names it if something else needs it. Code outside the blocks is untouched, so a one-line skeleton is a valid starting point. Rust target only: a Pythonobject/block needs a class around it.The roll-out happens in memory before stage 3, so the new blocks join
declaredand--check(#746) reports a file with pending blocks as stale. It runs after--init, which rewrites files on disk;--inithonoursskipas well. Builtinffi.*keys are never rolled out. Twoprefixlines in one file, or one prefix declared by two files, fail the run (exit 2); an unknown prefix is only a warning.Changes
stub/cli.py:_roll_out_prefixesand_new_blocks, called once after--init, returning a failure count;_stage_2subtracts the run'sskipkeys.stub/consts.py:prefixandskipjoin the pipeline directive kinds.docs/packaging/stubgen.rst: the directive in the reference.tests/python/test_stubgen_rust.py: thetestingnamespace rolled out around an existing block, a skip, and a hand-written tail (--check1, in place 0,--check0); the same skeleton under--init(blocks written, skip honoured,--check0); a prefix declared twice; exact matching, insertion order, and the builtin exclusion with a stubbed registry.Testing
test_stubgen_rust.py+test_stubgen.py: 109 passed; pre-commit lint clean. Againstlibtvm_compiler.so, atirx.rswith the two lines above, one moreskip, and thirteenty-maplines for theirtypes rolls out 63 blocks in one run, leaves nosuper::reference, keeps the trailingmod tail {}, and passes--checkon the next run.