Skip to content

Commit 66fa445

Browse files
Apply suggestions from code review
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent b42a86a commit 66fa445

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Lib/test/test_descr.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,14 @@ class W(_testcapi.HeapCCollection):
13841384
a.foo = 42
13851385
self.assertIs(weakref.ref(a)(), a)
13861386

1387+
with self.assertRaises(TypeError):
1388+
class X(_testcapi.HeapCCollection):
1389+
__slots__ = ['x']
1390+
1391+
with self.assertRaises(TypeError):
1392+
class X(_testcapi.HeapCCollection):
1393+
__slots__ = ['__dict__', 'x']
1394+
13871395
@support.subTests(('base', 'arg'), [
13881396
(tuple, (1, 2, 3)),
13891397
(int, 9876543210**2),
@@ -1414,6 +1422,13 @@ class W(base):
14141422
self.assertIs(weakref.ref(a)(), a)
14151423
self.assertEqual(a, base(arg))
14161424

1425+
with self.assertRaises(TypeError):
1426+
class X(base):
1427+
__slots__ = ['x']
1428+
with self.assertRaises(TypeError):
1429+
class X(base):
1430+
__slots__ = ['__dict__', 'x']
1431+
14171432
def test_slots_special2(self):
14181433
# Testing __qualname__ and __classcell__ in __slots__
14191434
class Meta(type):

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4643,7 +4643,7 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type, PyObject *dict
46434643
Py_ssize_t nslot = PyTuple_GET_SIZE(et->ht_slots);
46444644
if (ctx->base->tp_itemsize != 0) {
46454645
PyErr_Format(PyExc_TypeError,
4646-
"nonempty __slots__ not supported for subtype of '%s'",
4646+
"arbitrary __slots__ not supported for subtype of '%s'",
46474647
ctx->base->tp_name);
46484648
return -1;
46494649
}

0 commit comments

Comments
 (0)