Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stacked singledispatches use wrong type annotation #8872

Closed
anntzer opened this issue Feb 11, 2021 · 0 comments
Closed

stacked singledispatches use wrong type annotation #8872

anntzer opened this issue Feb 11, 2021 · 0 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Feb 11, 2021

Describe the bug

When multiple @functools.singledispatch decorators are stacked (as documented by the stdlib docs at https://docs.python.org/3/library/functools.html#functools.singledispatch), the type annotations reported by sphinx are incorrect.

To Reproduce
Steps to reproduce the behavior:

cat >project.py <<EOF
from functools import singledispatch

@singledispatch
def foo(x): "something"

@foo.register(int)
@foo.register(float)
def _(x): "a number"
EOF
sphinx-apidoc . -o . -F -A me -V 0.0
PYTHONPATH=. make html

then open _build/html/project.html: you get

project.foo(x)                 [source]
project.foo(x: float)
project.foo(x: float)
something

Expected behavior
The correct overloads are

project.foo(x)
project.foo(x: int)
project.foo(x: float)

Your project
N/A

Screenshots
N/A

Environment info

  • OS: Arch Linux
  • Python version: 3.9.1
  • Sphinx version: 3.4.3
  • Sphinx extensions: sphinx.ext.autodoc
  • Extra tools: N/A

Additional context
N/A

@tk0miya tk0miya added this to the 4.0.0 milestone Feb 12, 2021
@tk0miya tk0miya modified the milestones: 4.0.0, 4.1.0 Apr 19, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue May 2, 2021
…ndered

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.
tk0miya added a commit to tk0miya/sphinx that referenced this issue May 2, 2021
…ndered

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.
tk0miya added a commit to tk0miya/sphinx that referenced this issue May 2, 2021
…ndered

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.
@tk0miya tk0miya closed this as completed in caa6579 May 3, 2021
tk0miya added a commit that referenced this issue May 3, 2021
Fix #8872: autodoc: stacked singledispatches are wrongly rendered
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants