sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.45k stars 2.1k forks source link

autodoc events for singledispatchmethod receive None for name instead of str #10529

Open elfjes opened 2 years ago

elfjes commented 2 years ago

Describe the bug

When autodoc-ing a functools.singledispatchmethod, the MethodDocumenter for the registered dispatchers do not receive/parse a valid fullname, which then cause the event handlers for this method to be called with None as the name argument instead of their actual name.

How to Reproduce

foo.py

import functools

class Foo:
    @functools.singledispatchmethod
    def bar(self, a):
        pass

    @bar.register
    def dispatch(self, a: int):
        pass

index.rst

foo module
==========

.. automodule:: foo
   :members:
   :undoc-members:
   :show-inheritance:

conf.py

import os
import sys
sys.path.insert(0, os.path.abspath('.'))

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

def autodoc_signature(app, what, name, obj, options, signature, return_annotation):
    if name is None:
        raise ValueError("name must not be None")

def setup(app):
    app.connect('autodoc-process-signature', autodoc_signature)
$ # create above files
$ pip install -U sphinx
$ sphinx-build -T -W -a . ./build
$ # see traceback on screen

Expected behavior

autdoc event handlers should always be called with the name argument set

Your project

-

Screenshots

No response

OS

all

Python version

3.8+

Sphinx version

5.0.1

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

cdreimer-thewriter commented 2 years ago

Not sure if related to this bug or a separate bug. For my dispatch methods, I have the @staticmethod decorator underneath the @singledispatchmethod and @methodname.register(type) decorators. The word static is not appearing next to the method name.