[New-bugs-announce] [issue46132] Attempting to create an enum with slots silently fails

Alex Waygood report at bugs.python.org
Sun Dec 19 08:47:18 EST 2021


New submission from Alex Waygood <Alex.Waygood at Gmail.com>:

Attempting to create an enum with __slots__ silently fails. No error is raised if __slots__ are specified, but the usual behaviour of __slots__ does not work as expected. Attributes that are not specified in __slots__ can be freely set:


>>> from enum import Enum
>>> class Color(Enum):
...     __slots__ = ()
...     RED = 0
...     BLUE = 1
...
>>> Color.RED.foo = 'bar'
>>>


Given that enums are rather special, I didn't exactly *expect* this to work -- but it might be good to raise some kind of error if a user attempts to specify __slots__, instead of having it fail silently.

----------
messages: 408898
nosy: AlexWaygood, ethan.furman
priority: normal
severity: normal
status: open
title: Attempting to create an enum with slots silently fails
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

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


More information about the New-bugs-announce mailing list