How do I put docstrings on Enums?

前端 未结 2 1218
春和景丽
春和景丽 2020-12-09 16:58

Python 3.4 has a new enum module and Enum data type. If you are unable to switch to 3.4 yet, Enum has been backported.

Since Enum members support docstrings, as pre

2条回答
  •  半阙折子戏
    2020-12-09 17:55

    Functions and classes have docstrings, but most objects don't and do not even need them at all. There is no native docstring syntax for instance attributes, as they can be described exhaustively in the classes' docstring, which is also what I recommend you to do. Instances of classes normally also don't have their own docstrings, and enum members are nothing more than that.

    Sure enough you could add a docstring to almost anything. Actually you can, indeed, add anything to almost anything, as this is the way python was designed. But it is neither useful nor clean, and even what @Ethan Furman posted seems like way to much overhead just for adding a docstring to a static property.

    Long story short, even though you might not like it at first: Just don't do it and go with your enum's docstring. It is more than enough to explain the meaning of its members.

提交回复
热议问题