Python 3: Sphinx doesn't display type hints correctly

I am creating the HTML documentation for the Python 3 module automatically from my docstrings reStructuredText of my functions using Sphinx (make HTML). The generated HTML documentation still looks like it, but the parameter types of function signatures that are indicated in the source code as hints of the PEP484 type are not displayed correctly.

eg. this is an example of output from an HTML document generated by the Sphinx from one of my functions:

static parse_from_file(filename: str) → list Parses stuff from a text file. Parameters: filename – the filepath of a textfile to be parsed Returns: list of parsed elements 

This is what I expect from him:

 static parse_from_file(filename) Parses stuff from a text file. Parameters: filename (str) – the filepath of a textfile to be parsed Returns: list of parsed elements Return type: list 

Here's what the Python code looks like:

 def parse_from_file(filename: str) -> list: """Parses stuff from a text file. :param filename: the filepath of a textfile to be parsed :returns: list of parsed elements """ return [] 

How can I get Sphinx to correctly display hints like Python 3?

+5
source share
1 answer

I solved this myself using the sphinx-autodoc-typehints extension .

+5
source

Source: https://habr.com/ru/post/1258290/


All Articles