Skip to content

Enum _sunder_ exclusion is overly strict #118650

Description

@chrysn

Bug report

Bug description:

Enums' exclusive access to _sunder_ members inhibits their use with the IPython/Jupyter pattern of making HTML and other visual reprs available:

from enum import Enum

class MyEnum(Enum):
    A = 1

    def _repr_html_(self):
        return f'<span title="A MyEnum">{self}</abbr>'
# ValueError: _sunder_ names, such as '_repr_html_', are reserved for future Enum use

While having exclusive access to some space is valuable, and prefixing enum's range is not practical (as that prefix would need to be repeated by users constructing the class), carving out some space for widespread functions that are not expected to conflict with Enum's internal use should be possible. I suggest that at least _repr_html_ should be allowed, possibly the whole _repr_ prefix.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions