domdfcoding / enum_tools

Tools to expand Python's enum module.
https://enum-tools.readthedocs.io/en/latest
GNU Lesser General Public License v3.0
8 stars 7 forks source link

sphinx autoenum does not work with Sphinx 7.2+: UnboundLocalError: cannot access local variable 'membername' where it is not associated with a value #77

Open adamtheturtle opened 1 year ago

adamtheturtle commented 1 year ago

Description

sphinx autoenum does not work with Sphinx 7.2+.

We get:

updating environment: [new config] 1 added, 0 changed, 0 removed
/Users/adam/.virtualenvs/enum_example/lib/python3.11/site-packages/enum_tools/autoenum.py:226: RemovedInSphinx80Warning: The tuple interface of ObjectMember is deprecated. Use (obj.__name__, obj.object) instead.
  if member[0] not in self.object.__members__.keys():

Exception occurred:
  File "/Users/adam/.virtualenvs/enum_example/lib/python3.11/site-packages/sphinx/ext/autodoc/__init__.py", line 779, in filter_members
    self.name, membername, member, exc, type='autodoc')
               ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'membername' where it is not associated with a value
The full traceback has been saved in /var/folders/kd/d94l0l2j6vs_5f52qthyrtj80000gn/T/sphinx-err-040l0gvj.log, if you want to report the issue to the developers.

Steps to Reproduce

pip install the following:

enum-tools==0.10.0

# This will cause a failure.
# Change this to 7.1.2 or lower to avoid the error.
sphinx==7.2.2  

Create the following files:

conf.py :

extensions = ['sphinx.ext.autodoc', 'enum_tools.autoenum']

index.rst :

.. autoenum:: enum_tools.demo.People
    :members:

Run:

sphinx-build -M html . build

Actual result:

updating environment: [new config] 1 added, 0 changed, 0 removed
/Users/adam/.virtualenvs/enum_example/lib/python3.11/site-packages/enum_tools/autoenum.py:226: RemovedInSphinx80Warning: The tuple interface of ObjectMember is deprecated. Use (obj.__name__, obj.object) instead.
  if member[0] not in self.object.__members__.keys():

Exception occurred:
  File "/Users/adam/.virtualenvs/enum_example/lib/python3.11/site-packages/sphinx/ext/autodoc/__init__.py", line 779, in filter_members
    self.name, membername, member, exc, type='autodoc')
               ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'membername' where it is not associated with a value
The full traceback has been saved in /var/folders/kd/d94l0l2j6vs_5f52qthyrtj80000gn/T/sphinx-err-040l0gvj.log, if you want to report the issue to the developers.

Expected result:

No error.

Reproduces how often:

Easily reproduced.

Version

Installation source

pip

adamtheturtle commented 1 year ago

My guess is that this is a combination of errors, and the particular UnboundLocalError from https://github.com/sphinx-doc/sphinx/blob/6183b6abee561fc71c88fc66416d31a8f8ca009f/sphinx/ext/autodoc/__init__.py#L775-L777 is a Sphinx error.

adamtheturtle commented 1 year ago

Fix proposal for the Sphinx logging error: https://github.com/sphinx-doc/sphinx/pull/11628/files