Skip to content

Enum _sunder_ exclusion is overly strict #118650

Closed

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

  1. added
    type-bugAn unexpected behavior, bug, or error
    on May 6, 2024
  2. added 2 commits that reference this issue on May 6, 2024
  3. terryjreedy commented on May 6, 2024

    @terryjreedy
    Member

    The current sundar section makes no mention of a blanket preemption, but does doc that there have been additions, implying possible future additions. There is one current use of a name with internal underscores. This might be classified as type-feature, but type-bug is not clearly wrong.

    I think the restriction should be loosened at least in 3.13 if possible and documented whatever it is in each version.
    @ethanfurman

  4. added a commit that references this issue on May 7, 2024
  5. added 3 commits that reference this issue on May 7, 2024
  6. added a commit that references this issue on May 7, 2024
  7. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on May 7, 2024
  8. added 2 commits that reference this issue on May 8, 2024
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