Repository navigation
fix(ffi): a Python module lists its exports in __all__ - #925
Conversation
Quest-Claim: e0be21bf23c65d4a
A Rust pub fn whose name starts with `_` declared a stub pyright strict reported as an unused private function. Listing every export in __all__ counts each as used, and makes `from <prefix> import *` reach it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pub fn __all__ overwrote the module's export list. Every __x__ name now takes a trailing _, as other taken names do. Adds a follow-up for C++, which reserves such names too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Maintainer decision (taken while the maintainer is away, on their instruction to choose what is strongly recommended): /quest-merge. Keep the follow-up quest/m1/ffi-export/cpp-reserved-names.md, escaping reserved names in C++ and turning on clang's (Written by Opus 5.5) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
ℹ️ No critical issues — one minor gap inline.
Approach: sound. It builds __all__ from the generator's own name table rather than a second list, which fixes pyright's reportUnusedFunction at its cause, and reserving the whole __x__ family in Gen::claim is the general fix for the __all__ clash, not a special case for one name.
Reviewed changes
Reviewed the full diff at 0e1fb0b: the generator change, the fixture items, the import * test, the regenerated surfaces, and the quest files.
__all__in the module head:g.namesminusTAKEN, plus the runtime'sDuration,ForeignReader,Mut, andWaker, all of whichruntime/rt.pydefines unconditionally.- One name table:
Bound(only when a range bound exists),ArrayU8x<n>, and the range classes are now recorded ing.nameswhere they are emitted. - Dunder reservation: a module-level
__x__takes a trailing_, and a name ending in___counts as free, so the rename terminates. - Fixture and test:
pub fn _deprecatedandpub fn __all__, plus anexec("from api import *")check against the module's real namespace. That check catches a name listed but never bound, and a name bound but not listed. For moq, pyright'sreportUnsupportedDunderAllinjust moqcovers the first case.
claude-opus-5-5 | 𝕏
|
quest land watch: ended this pull request's pick, disarming its auto-merge, since its head 0e1fb0b is held by finding by pullfrog[bot]: (written by quest land watch) |
The generated module imports inspect as _inspect for the runtime's isawaitable check, but TAKEN missed it. Hoist the imports into IMPORTS and test that every alias it binds, and every _ name the runtime binds at module level, is in TAKEN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta from 0e1fb0b to 2b83610, which answers the earlier _inspect note.
_inspectreserved: added toTAKEN, so apub fn _inspectexports as_inspect_and no longer rebinds the aliasruntime/rt.pyreads.IMPORTSconst: the import header moved out of theheadformat string with identical output.module_names_takentest: checks that every import alias and every module-level_name inrt.pyis inTAKEN. I checked the current names (_Future,_Wakeup,_wakeups,_resume,_drains,_wakeup,_Pollable,_Const,_Dataclass,_Record) against the list.
claude-sonnet-5-5 | 𝕏
Merging this PR will degrade performance by 3.57%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |

Finishes
quest/m1/ffi-export/python-private-names.md(planned in kixel-ai/rust2#870, added by kixel-ai/rust2#900), which this deletes.A Rust
pubitem whose name starts with_now generates a Python module that pyright strict accepts. The generated module lists every export in a sorted__all__.Changes
ffi/src/python.rs: the module's head now declares__all__, built from the generator's name table (Gen::names) minus the runtime's private names (TAKEN), plus the runtime's public classes (Duration,ForeignReader,Mut,Waker).Bound, each range class (BoundU64, ...), and eachArrayU8x<n>class are now recorded in that table where they are emitted, so__all__comes from one source.__all__as accessed. So a function stub that is declared underif TYPE_CHECKING:and bound from the library inelse:no longer reportsreportUnusedFunctionwhen its name is private (_deprecated_).from <prefix> import *now reaches underscore-named exports and constants made by__getattr__. It no longer leaksannotations(thefrom __future__feature object).__x__name as taken (Gen::claim), so apub fn __all__exports as__all___instead of overwriting the export list. The same applies to__getattr__,__name__,__doc__, and the rest. A name ending in___counts as free, so the rename terminates. (Found in review round 1.)_inspect(Pullfrog's finding on the last head):TAKENnow holds the module'sinspectalias, so apub fn _inspectexports as_inspect_and can no longer rebind the alias thatruntime/rt.py's awaitable check reads. The import header moved into anIMPORTSconst, and a new test,module_names_taken, checks that every alias it binds and every_nameruntime/rt.pybinds at module level is inTAKEN.pub fn __all__. It also addspub fn _deprecatedat the crate root. Its Python name is_deprecated_, because the module's own_deprecateddecorator already takes_deprecated. Every binding names it apart fromdeprecated: Capi__deprecated, Swift/Kotlin/Dartdeprecated_, GoDeprecated__.tests/api.py(idioms): runsfrom api import *, calls_deprecated_and__all___, and checks that the imported names are exactly the module's public bindings, plus those two, plus the constants made by__getattr__.ffi/README.md: one line on__all__.surface/: regenerated.Public API
Python bindings gain
__all__. This is a behavior change forimport *: it now includes underscore-named exports and constants, and dropsannotations. Nothing is breaking. There is no wire change and no other binding changes.Decisions
__all__rather than drop the fixture item.__all__also includes the runtime's public classes (Duration,ForeignReader,Mut,Waker, andBoundwhere a range bound exists) and the array and range classes, because signatures name them and a star import should give a caller what annotations spell. Alternative: only Rust items. Rejected because a star-importing caller could not nameDuration.__all__is placed after the imports, sorted, as a list. A tuple would behave the same; the list is the common convention and both checkers accept it._deprecated, at the crate root. Inside a module (clash::_x), the Python name gets aclash_prefix and the bug does not reproduce. The name also collides with the module's own_deprecated, which exercises the trailing-_rename.__x__name is reserved at module level, not only__all__, because Python defines the whole family and a list of known names would go stale._inspectfinding with a test over the whole class of names (every import alias and every runtime module-level_name) rather than only adding one entry. Alternative: add the entry alone. Rejected because the list had already drifted once.Validation
api_py_typesfailed withapi.py:7398:6 - error: Function "_deprecated_" is not accessed (reportUnusedFunction). With the change, it passes under both mypy and pyright strict.import *assertion inapi.py idiomscompares__all__against the loaded module's own namespace. Its first run caughtArrayU8x4,BoundU64, andBoundsU64missing from the name table; they were fixed before landing.module_names_takenfails with "the module's_inspectis not in TAKEN" when the entry is removed, and passes with it. A separate script scan of the import header,rt.py, andnative.pyfound no other missing name.just cipasses (ffi fixtures: 73 passed, 27 ignored as nightly or sanitizer jobs).Caused by
None: the bug is as old as the module's scheme of declaring stubs under
TYPE_CHECKING, and no fixture had a top-level name starting with_until now.Follow-ups
quest/m1/ffi-export/cpp-reserved-names.md[S]: the fixture'spub fn __all__renders in C++ asapi::__all__, and C++ reserves every identifier containing__. It compiles today. Recommended fix, recorded in its Plan: escape the name and claim it throughnamedinffi/src/cpp.rs, then turn on-Wreserved-identifierin the strict build. No open decisions. Open PR #919 covers names that headers define as macros, not this.Models
Size: S
Implementer: Claude, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, S)
🤖 Generated with Claude Code
(Written by Claude Opus 5.5)
Review
Rewritten by
quest reviewafter each round.Head: 2b83610
Base: origin/main at 24ff182
Risk: high,
Generated Python public API names change for consumers exporting reserved names, so affected bindings may require regeneration and redistribution.Classified: medium by default
Reviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1f99c-c9ce-7521-8fc0-e3c3ce2582c9, round 4Score: 10/10,
The incremental change reserves the missing _inspect alias and extracts imports without changing their output, with no new findings.Raised the risk to high:
Generated Python public API names change for consumers exporting reserved names, so affected bindings may require regeneration and redistribution.Rounds: 4; first round 1 (medium 1); findings 1 (medium 1): fixed 1, refuted 0, open 0
Findings: none
Summary by CodeRabbit
__all__lists that identify their public exports.Summary by CodeRabbit
New Features
Bug Fixes
Documentation