[New-bugs-announce] [issue43814] Fix the error message for disallowed __weakref__ slots

Géry report at bugs.python.org
Mon Apr 12 09:55:17 EDT 2021


New submission from Géry <gery.ogam at gmail.com>:

When

```
TypeError: __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0
```

is raised, the second condition `base->tp_itemsize != 0` (i.e. the base is a *variable-length* type, like `int`, `tuple` and `bytes`) in the error message is impossible since using a non-empty `__slots__` (e.g. `__slots__ = ('__weakref__',)`) for a subtype of a variable-length type raises a

```
TypeError: nonempty __slots__ not supported for subtype of '…'
```

earlier in the `type.__new__` implementation.

----------
components: Interpreter Core
messages: 390851
nosy: maggyero
priority: normal
severity: normal
status: open
title: Fix the error message for disallowed __weakref__ slots
type: enhancement
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43814>
_______________________________________


More information about the New-bugs-announce mailing list