Sphinx: Python 3.4 enum classes not working

Created on 3 Jan 2015  路  13Comments  路  Source: sphinx-doc/sphinx

I tried something like


.. autoclass:: lensfunpy.ModifyFlags
   :members:
   :undoc-members:

but it only prints the class name without the enum members. Does this need some new support or does the enum implementation need to be more doc-friendly?


bug

Most helpful comment

Confirmed. It works fine to me too.

  • Sphinx-1.5a2
  • Python-3.5.2
  • Windows 10

foo.py:

import enum


class E(enum.Enum):
    """
    this is enum class
    """

    val1 = 1  #: doc
    val2 = 2  #: doc


Animal = enum.Enum('Animal', 'ant bee cat dog')  #: this is doc string

index.rst:

.. automodule:: foo
   :members:
   :undoc-members:

Result:
image

All 13 comments

_From Georg Brandl on 2014-10-27 20:53:03+00:00_

enums are special enough that I think they warrant some special casing.

Seems to work partly now. It prints the enum members but the members' doc string is not printed.

@neothemachine what version are you using? Doesn't work for me on neither py2 or py3 with latest version from master

@rossengeorgiev See https://pythonhosted.org/rawpy/api/enums.html Uses sphinx 1.4

@naokisatoname That's strange. I get no members listed, even with :undoc-members:. If I specify a docstring to any member the value is showing as None. If I list members with :members: a b c those members show up in docs as expected with their correct value.

Python3 with sphinx 1.5a0

After looking into the sphinx source code, I notice that if it looks up the members using __dict__, doesn't contain any members. However, if I add :inherited-members:, it will lookup the members using dir(), which will in fact return the members. Works for me on py2.7 with sphinx 1.4 and py3.4 with sphinx 1.5a1.

Adding :inherited-members: will show Enum members as expected, including docstrings.

Confirmed. It works fine to me too.

  • Sphinx-1.5a2
  • Python-3.5.2
  • Windows 10

foo.py:

import enum


class E(enum.Enum):
    """
    this is enum class
    """

    val1 = 1  #: doc
    val2 = 2  #: doc


Animal = enum.Enum('Animal', 'ant bee cat dog')  #: this is doc string

index.rst:

.. automodule:: foo
   :members:
   :undoc-members:

Result:
image

Actually, I don't know which sphinx versions are not good. Anyway, it works with sphinx-1.4 and 1.5.

Sphinx project I tested with: 1609.zip

Would it be possible to display just the value? Enum will create this verbose repr <Animal.ant: 1>, which can get pretty difficult to read when class and property names are long. Especially when there are a dozen or more properties.

@rossengeorgiev It might be possible. However it is another feature request. Can you create new feature request issue please?

I get this problem in Python 3.4.3 and 3.4.4 but not 3.5.2, and not with 2.7.11 using enum34 from PyPI.

@evanunderscore confirmed. I created another issue #3255. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shimizukawa picture shimizukawa  路  3Comments

MichiK picture MichiK  路  3Comments

eine picture eine  路  3Comments

shimizukawa picture shimizukawa  路  3Comments

susmita1d picture susmita1d  路  3Comments