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).
This commit is contained in:
Changjoon
2026-04-27 21:39:21 +09:00
committed by GitHub
parent f10f441854
commit dc81c740cf
2 changed files with 2 additions and 4 deletions

View File

@@ -4952,7 +4952,6 @@ class ClassPropertiesAndMethods(unittest.TestCase):
with self.assertRaises(TypeError):
a + a
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slot_shadows_class_variable(self):
with self.assertRaises(ValueError) as cm:
class X:
@@ -4961,7 +4960,6 @@ class ClassPropertiesAndMethods(unittest.TestCase):
m = str(cm.exception)
self.assertEqual("'foo' in __slots__ conflicts with class variable", m)
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_set_doc(self):
class X:
"elephant"

View File

@@ -2004,7 +2004,7 @@ impl Constructor for PyType {
// Check if slot name conflicts with class attributes
if attributes.contains_key(vm.ctx.intern_str(slot.as_wtf8())) {
return Err(vm.new_value_error(format!(
"'{}' in __slots__ conflicts with a class variable",
"'{}' in __slots__ conflicts with class variable",
slot.as_wtf8()
)));
}
@@ -2404,7 +2404,7 @@ impl Py<PyType> {
// Similar to CPython's type_set_doc
let value = value.ok_or_else(|| {
vm.new_type_error(format!(
"cannot delete '__doc__' attribute of type '{}'",
"cannot delete '__doc__' attribute of immutable type '{}'",
self.name()
))
})?;