How to extend Python Enum?

后端 未结 7 1033
广开言路
广开言路 2020-12-08 18:26

What is best practice for extending Enum type in Python 3.4 and is there even a possibility for do this?

For example:

from enum import E         


        
相关标签:
7条回答
  • 2020-12-08 19:08

    Subclassing an enumeration is allowed only if the enumeration does not define any members.

    Allowing subclassing of enums that define members would lead to a violation of some important invariants of types and instances.

    https://docs.python.org/3/library/enum.html#restricted-subclassing-of-enumerations

    So no, it's not directly possible.

    0 讨论(0)
提交回复
热议问题