mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
When multiple singledispatch decorators are stacked, the first typehints are copied to the subsequent definitions unexpectedly. Now autodoc generates a dummy function not to affect typehints to subsequent functions.
29 lines
542 B
Python
29 lines
542 B
Python
import inspect
|
|
from functools import singledispatch
|
|
|
|
|
|
def assign_signature(func):
|
|
# This is intended to cover more complex signature-rewriting decorators.
|
|
func.__signature__ = inspect.signature(func)
|
|
return func
|
|
|
|
|
|
@singledispatch
|
|
def func(arg, kwarg=None):
|
|
"""A function for general use."""
|
|
pass
|
|
|
|
|
|
@func.register(int)
|
|
@func.register(float)
|
|
def _func_int(arg, kwarg=None):
|
|
"""A function for int."""
|
|
pass
|
|
|
|
|
|
@func.register(str)
|
|
@assign_signature
|
|
def _func_str(arg, kwarg=None):
|
|
"""A function for str."""
|
|
pass
|