You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enums' exclusive access to _sunder_ members inhibits their use with the IPython/Jupyter pattern of making HTML and other visual reprs available:
fromenumimportEnumclassMyEnum(Enum):
A=1def_repr_html_(self):
returnf'<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.
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
Activity
pythongh-118650: Exclude `_repr_*` methods from Enum's _sunder_ reser…
pythongh-118650: Exclude `_repr_*` methods from Enum's _sunder_ reser…
terryjreedy commentedon May 6, 2024
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, buttype-bugis 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
gh-118650: Exclude `_repr_*` methods from Enum's _sunder_ reservation (…
pythongh-118650: Document `Enum._repr_*` reservation exclusion
pythongh-118650: Document `Enum._repr_*` reservation exclusion
pythongh-118650: Document `Enum._repr_*` reservation exclusion
gh-118650: Document `Enum._repr_*` reservation exclusion (GH-118698)
pythongh-118650: Exclude `_repr_*` methods from Enum's _sunder_ reser…
pythongh-118650: Document `Enum._repr_*` reservation exclusion (pytho…