Skip to content

BUG: Autosummary may fail on global variables with overriden __eq__ #8583

@timothydijamco

Description

@timothydijamco

This is specific to 3.4.0

Autosummary may fail on a global variable whose value is an object with an __eq__ implementation that raises an error.

Example

For example, let's say I have a module that looks like this:

class Foo:
    def __eq__(self, other):
        if not isinstance(other, Foo):
            raise TypeError('Foo objects cannot be compared to non-Foo objects')

foo = Foo()
  • There is a global variable foo
  • Its value is an object whose __eq__ behavior is strict, and may raise an error

When running Sphinx, autosummary will fail.

...
reading sources... [100%] generated/mymodule.foo

Exception occurred:
  File "/root/sphinx-eq-bug-repro/mymodule/__init__.py", line 4, in __eq__
    raise TypeError('Foo objects cannot be compared to non-Foo objects')
TypeError: Foo objects cannot be compared to non-Foo objects

(This code example is a little contrived but hopefully it illustrates well enough—it's a very simplified version of our actual use case)

To Reproduce
I have a minimal repro here: https://github.com/timothydijamco/sphinx-eq-bug-repro

Running the below will hit the error if using Sphinx 3.4.0 (but not with Sphinx 3.3.1).

$ git clone https://github.com/timothydijamco/sphinx-eq-bug-repro.git
$ cd sphinx-eq-bug-repro
$ cd docs
$ make html

Expected behavior
Sphinx should finish building successfully (it builds OK when using 3.3.1).

Environment info

  • Python version: 3.9.0
  • Sphinx version: 3.4.0
  • Sphinx extensions: sphinx.ext.autosummary

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions