mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Reject a fifth argument to property() (#8510)
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
This commit is contained in:
1 parent
901d8e186e
commit
0b150ca569
2 files changed
+8
-5
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/*! Python `property` descriptor class.
|
||||
|
||||
*/
|
||||
use super::{PyStrRef, PyType};
|
||||
use super::PyType;
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::function::{IntoFuncArgs, PosArgs};
|
||||
use crate::{
|
||||
@@ -41,8 +41,6 @@ pub struct PropertyArgs {
|
||||
fdel: Option<PyObjectRef>,
|
||||
#[pyarg(any, default)]
|
||||
doc: Option<PyObjectRef>,
|
||||
#[pyarg(any, default)]
|
||||
name: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
impl GetDescriptor for PyProperty {
|
||||
@@ -221,7 +219,6 @@ impl PyProperty {
|
||||
fset: new_setter.or_else(|| zelf.fset()),
|
||||
fdel: new_deleter.or_else(|| zelf.fdel()),
|
||||
doc,
|
||||
name: None,
|
||||
};
|
||||
|
||||
// Create new property using py_new and init
|
||||
@@ -401,7 +398,6 @@ impl Initializer for PyProperty {
|
||||
*zelf.getter.write() = args.fget;
|
||||
*zelf.setter.write() = args.fset;
|
||||
*zelf.deleter.write() = args.fdel;
|
||||
*zelf.name.write() = args.name.map(|a| a.as_object().to_owned());
|
||||
zelf.getter_doc.store(getter_doc, Ordering::Relaxed);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -85,3 +85,10 @@ assert p1.__get__(None, object) is p1
|
||||
|
||||
p2 = property("a", doc="pdoc")
|
||||
# assert p2.__doc__ == 'pdoc'
|
||||
|
||||
|
||||
# property() takes at most four arguments, and `name` is not one of them:
|
||||
# the name slot is filled by __set_name__ and the __name__ setter instead.
|
||||
assert_raises(TypeError, property, None, None, None, None, None)
|
||||
assert_raises(TypeError, property, "a", "b", "c", "d", "e")
|
||||
assert_raises(TypeError, property, name="x")
|
||||
Reference in new issue
Block a user