Skip to content

Commit dc81c74

Browse files
Match CPython wording for __slots__ conflict and __doc__ delete errors (#7698)
The behavior already matched CPython (the slot conflict is detected, the __doc__ delete is rejected); only the message text drifted. - "__slots__ conflicts with a class variable" -> drop the stray "a" to match CPython's "conflicts with class variable". - "cannot delete '__doc__' attribute of type 'X'" -> insert "immutable" before "type" to match CPython's wording (CPython surfaces the same phrase even for user-defined classes since the descriptor refuses the delete unconditionally).
1 parent f10f441 commit dc81c74

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

Lib/test/test_descr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4952,7 +4952,6 @@ class A(int):
49524952
with self.assertRaises(TypeError):
49534953
a + a
49544954

4955-
@unittest.expectedFailure # TODO: RUSTPYTHON
49564955
def test_slot_shadows_class_variable(self):
49574956
with self.assertRaises(ValueError) as cm:
49584957
class X:
@@ -4961,7 +4960,6 @@ class X:
49614960
m = str(cm.exception)
49624961
self.assertEqual("'foo' in __slots__ conflicts with class variable", m)
49634962

4964-
@unittest.expectedFailure # TODO: RUSTPYTHON
49654963
def test_set_doc(self):
49664964
class X:
49674965
"elephant"

crates/vm/src/builtins/type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ impl Constructor for PyType {
20042004
// Check if slot name conflicts with class attributes
20052005
if attributes.contains_key(vm.ctx.intern_str(slot.as_wtf8())) {
20062006
return Err(vm.new_value_error(format!(
2007-
"'{}' in __slots__ conflicts with a class variable",
2007+
"'{}' in __slots__ conflicts with class variable",
20082008
slot.as_wtf8()
20092009
)));
20102010
}
@@ -2404,7 +2404,7 @@ impl Py<PyType> {
24042404
// Similar to CPython's type_set_doc
24052405
let value = value.ok_or_else(|| {
24062406
vm.new_type_error(format!(
2407-
"cannot delete '__doc__' attribute of type '{}'",
2407+
"cannot delete '__doc__' attribute of immutable type '{}'",
24082408
self.name()
24092409
))
24102410
})?;

0 commit comments

Comments
 (0)