mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-95077: [Enum] add code-based deprecation warnings for member.member access (GH-95083)
* issue deprecation warning for member.member access * always store member property in current class * remove __getattr__
This commit is contained in:
parent
73ee5a6b86
commit
4e704d7847
5 changed files with 61 additions and 68 deletions
|
@ -945,23 +945,12 @@ but remain normal attributes.
|
|||
""""""""""""""""""""
|
||||
|
||||
Enum members are instances of their enum class, and are normally accessed as
|
||||
``EnumClass.member``. In Python versions ``3.5`` to ``3.10`` you could access
|
||||
members from other members -- this practice was discouraged, and in ``3.11``
|
||||
:class:`Enum` returns to not allowing it::
|
||||
|
||||
>>> class FieldTypes(Enum):
|
||||
... name = 0
|
||||
... value = 1
|
||||
... size = 2
|
||||
...
|
||||
>>> FieldTypes.value.size
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AttributeError: <enum 'FieldTypes'> member has no attribute 'size'
|
||||
|
||||
``EnumClass.member``. In Python versions starting with ``3.5`` you could access
|
||||
members from other members -- this practice is discouraged, is deprecated
|
||||
in ``3.12``, and will be removed in ``3.14``.
|
||||
|
||||
.. versionchanged:: 3.5
|
||||
.. versionchanged:: 3.11
|
||||
.. versionchanged:: 3.12
|
||||
|
||||
|
||||
Creating members that are mixed with other data types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue