Reject a fifth argument to property() - #8510
Conversation
PropertyArgs declared a fifth positional-or-keyword field, name, so the
derived arity was 0..=5 and property(None, None, None, None, None) built
a property object with the fifth argument stored in the __name__ slot.
CPython's property.__init__ is Argument Clinic generated with maxpos = 4
and the keyword list {fget, fset, fdel, doc}, so it rejects both that call
and property(name='x').
Drop the field. Nothing passed it: clone_property_with always supplied
None and copies the name separately, and the name slot is still filled by
__set_name__ and the __name__ setter.
Assisted-by: Claude Code:claude-opus-5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe property constructor no longer accepts a fifth positional argument or the unsupported ChangesProperty argument validation
Estimated code review effort: 2 (Simple) | ~10 minutes Mergeability Score: ⚪ Minimal · up to This localized change aligns property() argument handling with the documented behavior and includes regression coverage; no actionable merge-blocking risk remains after normal checks. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
ShaharNaveh
left a comment
There was a problem hiding this comment.
huh, weird that cpython doesn't have a test for it.
tysm!
property()accepts a fifth positional argument instead of raisingTypeError#8460Summary
PropertyArgsdeclared a fifth positional-or-keyword field,name, so the derived arity was0..=5andproperty(None, None, None, None, None)built apropertyobject with the fifth argument stored in the__name__slot. CPython'sproperty.__init__is Argument Clinic generated withmaxpos = 4and the keyword list{fget, fset, fdel, doc}, so it rejects both that call andproperty(name='x').AS-IS
TO-BE
(matching CPython, which raises
TypeErrorfor both; the message wording still comes fromFuncArgs::bindrather than CPython'sproperty() takes at most 4 arguments (5 given), which is a separate repo-wide difference)Changes
namefield fromPropertyArgsand the assignment that consumes it inInitializer::init, dropping the derived arity back to0..=4.name: Noneinitializer inclone_property_withand the unusedPyStrRefimport. ThePyPropertynameslot is untouched and is still filled by__set_name__and the__name__setter.extra_tests/snippets/builtin_property.pyfor the five-positional-argument andname=keyword forms.Test plan
Built and run on macOS aarch64 against upstream/main
525ba8cf0, using the CI feature set--no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env.propertyobject; with the patch both raiseTypeError. Four-argument construction, thegetter/setter/deleterbuilders and__set_name__still behave as before, and__set_name__still fills the name slot.cargo run --release -- -m test test_property test_descr test_builtin: 331 run, 36 skipped, all pass.cargo test --workspace --exclude rustpython-capi --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --features threading: 1107 pass, 0 fail.cargo testincrates/capi: 102 pass.extra_testsbuiltin snippets under RustPython: 66 of 67 pass, the newbuiltin_property.pycases among them. The one failure,builtin_thread.py, asserts_thread.TIMEOUT_MAX in [9223372036.0, 4294967.0]and my build reports2147483648, which is an unrelated platform constant.cargo fmt --checkclean,cargo clippy -p rustpython-vm --all-targetsreports nothing on the changed file, andpre-commit run --filespasses on both changed files.I used Claude Code (claude-opus-5) to draft the analysis, the patch and this description; I reviewed the change and ran every command above myself.
Summary by CodeRabbit
property()now correctly rejects more than four positional arguments.namekeyword arguments are now rejected.