sphinx-doc / sphinx-doc/sphinx
Typhint optional parameters with google style and pep484 typhints does not work.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
The autodoc_typehints = 'both' option does not work with optional parameters in Google Python
Style docs with pep484_type_annotations typed functions.
Just as a side note but not part of this issue:
The docs are completly missing in the signature for non pep484 style.
How to Reproduce
$ # Unzip.
$ pip install -r sphinx
$ cd unziped folder
$ make html
$ # open _build/html/index and see param2 in module_level_function vs module_level_function_pep484
Expected behavior
I would expect that param2 in docstring is documented the same and the type is added. so in module_level_function_pep484() is also param2 (str, optional) - The .....
Your project
Screenshots

OS
Debian GNU/Linux 11 (bullseye)
Python version
Python 3.8.12
Sphinx version
4.4.0
Sphinx extensions
'sphinx.ext.autodoc', 'sphinx.ext.napoleon'
Extra tools
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by unpacking docs.zip, installing the requirements, and running make html with sphinx.ext.autodoc and sphinx.ext.napoleon enabled. Compare the generated documentation for module_level_function and module_level_function_pep484; done means the optional parameter is documented consistently with its type and description.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100