Repository navigation
gh-112328: [Enum] Make some private attributes public. #112514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e732a33
ded4c56
0a353a6
b771360
88ddb4f
3b95b36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -868,16 +868,16 @@ Others | |
| While :class:`IntEnum` is part of the :mod:`enum` module, it would be very | ||
| simple to implement independently:: | ||
|
|
||
| class IntEnum(int, Enum): | ||
| class IntEnum(int, ReprEnum): # or Enum instead of ReprEnum | ||
| pass | ||
|
|
||
| This demonstrates how similar derived enumerations can be defined; for example | ||
| a :class:`FloatEnum` that mixes in :class:`float` instead of :class:`int`. | ||
|
|
||
| Some rules: | ||
|
|
||
| 1. When subclassing :class:`Enum`, mix-in types must appear before | ||
| :class:`Enum` itself in the sequence of bases, as in the :class:`IntEnum` | ||
| 1. When subclassing :class:`Enum`, mix-in types must appear before the | ||
| :class:`Enum` class itself in the sequence of bases, as in the :class:`IntEnum` | ||
| example above. | ||
| 2. Mix-in types must be subclassable. For example, :class:`bool` and | ||
| :class:`range` are not subclassable and will throw an error during Enum | ||
|
|
@@ -961,30 +961,36 @@ all the members are created it is no longer used. | |
| Supported ``_sunder_`` names | ||
| """""""""""""""""""""""""""" | ||
|
|
||
| - ``_name_`` -- name of the member | ||
| - ``_value_`` -- value of the member; can be set / modified in ``__new__`` | ||
|
|
||
| - ``_missing_`` -- a lookup function used when a value is not found; may be | ||
| overridden | ||
| - ``_ignore_`` -- a list of names, either as a :class:`list` or a :class:`str`, | ||
| that will not be transformed into members, and will be removed from the final | ||
| class | ||
| - ``_order_`` -- used in Python 2/3 code to ensure member order is consistent | ||
| (class attribute, removed during class creation) | ||
| - ``_generate_next_value_`` -- used by the `Functional API`_ and by | ||
| :class:`auto` to get an appropriate value for an enum member; may be | ||
| overridden | ||
|
|
||
| .. note:: | ||
|
|
||
| For standard :class:`Enum` classes the next value chosen is the last value seen | ||
| incremented by one. | ||
|
|
||
| For :class:`Flag` classes the next value chosen will be the next highest | ||
| power-of-two, regardless of the last value seen. | ||
| - :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing | ||
| member. | ||
| - :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an | ||
| existing member. | ||
| - :attr:`~Enum._name_` -- name of the member | ||
| - :attr:`~Enum._value_` -- value of the member; can be set in ``__new__`` | ||
| - :meth:`~Enum._missing_` -- a lookup function used when a value is not found; | ||
| may be overridden | ||
| - :attr:`~Enum._ignore_` -- a list of names, either as a :class:`list` or a | ||
| :class:`str`, that will not be transformed into members, and will be removed | ||
| from the final class | ||
| - :attr:`~Enum._order_` -- used in Python 2/3 code to ensure member order is | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can drop Python2 part.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping for now -- I'll probably change |
||
| consistent (class attribute, removed during class creation) | ||
|
ethanfurman marked this conversation as resolved.
Resolved
|
||
| - :meth:`~Enum._generate_next_value_` -- used to get an appropriate value for | ||
| an enum member; may be overridden | ||
|
|
||
| .. note:: | ||
|
|
||
| For standard :class:`Enum` classes the next value chosen is the highest | ||
| value seen incremented by one. | ||
|
|
||
| For :class:`Flag` classes the next value chosen will be the next highest | ||
| power-of-two. | ||
|
|
||
| .. versionchanged:: 3.13 | ||
| Prior versions would use the last seen value instead of the highest value. | ||
|
|
||
| .. versionadded:: 3.6 ``_missing_``, ``_order_``, ``_generate_next_value_`` | ||
| .. versionadded:: 3.7 ``_ignore_`` | ||
| .. versionadded:: 3.13 ``_add_alias_``, ``_add_value_alias_`` | ||
|
|
||
| To help keep Python 2 / Python 3 code in sync an :attr:`_order_` attribute can | ||
| be provided. It will be checked against the actual order of the enumeration | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.