Navigation Menu

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

Fixed singledispatch documentation #10285

Merged
merged 5 commits into from Apr 4, 2022
Merged

Fixed singledispatch documentation #10285

merged 5 commits into from Apr 4, 2022

Conversation

jmp1985
Copy link
Contributor

@jmp1985 jmp1985 commented Mar 21, 2022

Subject: Single dispatch functions were not documented due to minor bug which this pull request fixes

Feature or Bugfix

  • Bugfix
  • Refactoring

Purpose

  • Previously, singledispatch functions never had their variants documented. This bugfix results in the variants being documented.

Detail

Here is a minimal example package which shows the error:
bug_example.zip

Here is an old picture of the output:
sphinx_old

Here is new picture of the output which is what I think is intended:
sphinx-new

@tk0miya
Copy link
Member

tk0miya commented Mar 26, 2022

Could you add a testcase, please?

@jmp1985
Copy link
Contributor Author

jmp1985 commented Apr 1, 2022

Hi @tk0miya. I would be happy to add a test case but would you be able to point me to an example test or template I could follow?

@tk0miya
Copy link
Member

tk0miya commented Apr 3, 2022

Please check these files:

They confirms the result of autodoc for singledispatch functions and methods. I think this change should change (add?) something new to these testcases.

@tk0miya tk0miya added this to the 5.0.0 milestone Apr 3, 2022
@jmp1985
Copy link
Contributor Author

jmp1985 commented Apr 4, 2022

Thanks @tk0miya

I have added the test cases. It turned out that with single dispatch if you register the variants as follows everything works fine:

@func.register(int)
def func_int(arg):
    pass

However, if you use type annotations as follows then sphinx would not work:

@func.register
def func_int(arg: int):
    pass

This pull request now fixes this behaviour and adds a test case for functions registered using type annotations.

Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your update. I don't know singledispatch now supports type annotated functions and methods.
https://docs.python.org/3/library/functools.html#functools.singledispatch

LGTM!

@tk0miya tk0miya changed the base branch from master to 5.x April 4, 2022 14:40
@tk0miya tk0miya merged commit f5b3804 into sphinx-doc:5.x Apr 4, 2022
tk0miya added a commit that referenced this pull request Apr 4, 2022
@tk0miya
Copy link
Member

tk0miya commented Apr 4, 2022

Merged. Thank you for your contribution!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants