Repository navigation
Give os.chmod a valid __text_signature__ and keyword arguments - #8968
Conversation
posix.chmod took dir_fd between path and mode. Since RustPython#8807 renders each argument's parameter kind, that put `/` after `*`, which inspect cannot parse, and path and mode stayed positional-only, so os.chmod(path=..., mode=...) raised TypeError. A ChmodArgs struct follows CPython's order, as nt.chmod already does. path and mode are positional-or-keyword. follow_symlinks shows CPython's text through py_default, like LinkArgs. Assisted-by: Claude Code:claude-opus-5
The writer counts positional-only parameters up front and emits `/` when they run out, which assumes they come first in the Rust argument list. Nothing enforced that, and posix.chmod violated it. The signature is composed in a const context, so the assert fails the build and names the fix. Assisted-by: Claude Code:claude-opus-5
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe signature renderer now tracks emitted ChangesBuiltin signatures and chmod arguments
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change fixes the os.chmod signature so keyword arguments such as path and mode work. No concrete merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The change fixes keyword argument acceptance and signature metadata without changing permission-setting authority or filesystem target selection. No introduced or worsened security concern was identified in the reviewed changes. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation Issue
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| dir_fd: DirFd<'static, 0>, | ||
| // CPython writes the platform expression; on posix it is always true. | ||
| #[pyarg(named, default = true, py_default = "(os.name != 'nt')")] | ||
| follow_symlinks: bool, |
There was a problem hiding this comment.
what's the rationale not to use FollowSymlinks anymore?
There was a problem hiding this comment.
I did it to match CPython's __text_signature__. In CPython only os.chmod and os.link show follow_symlinks=(os.name != 'nt'), and the others show True. FollowSymlinks always renders True, and a flattened field can't take py_default, so I used a plain bool, the same way LinkArgs already does for os.link.
Because of that expression, inspect.signature(os.chmod) raises ValueError, same as in CPython. If you prefer to keep FollowSymlinks and show True, I'll switch it back.
There was a problem hiding this comment.
probably we can tweak FollowSymlinks to show proper value. but it is good for now
Merging this PR will not alter performance
Comparing Footnotes
|
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Thank you! |
One of checkbox below must be checked.
Summary
os.chmodwas the last native function whose__text_signature__was notvalid Python. It also rejected keyword arguments that CPython accepts.
The Rust arguments put the keyword-only
dir_fdbetweenpathandmode.Since #8807 renders each argument's kind,
*came out beforemodeand/after it. The same order made
pathandmodepositional-only, soos.chmod(path="f", mode=0o644)raisedTypeError.Changes
posix.chmodtakes aChmodArgsstruct in CPython's order, asnt.chmodalready does.
pathandmodeare positional-or-keyword./is not emitted after*,*argsor**kwargs. Signatures are composed in a const context, so a wrong argumentorder fails the build.
builtin_signature.pychecksos.chmod.Notes
whats_left.py --signaturedoes not change. CPython's ownos.chmodsignature is unparsable (its default is an expression), so both sides
record the same
ValueErrortext.inspect.signature(os.chmod)still raises, as in CPython.Assisted-by: Claude Code:claude-opus-5
Summary by CodeRabbit
os.chmodnow uses the platform-appropriate default forfollow_symlinks, improving consistency across operating systems.os.chmodcorrectly applies the requested symlink-following behavior.