pdoc
pdoc copied to clipboard
Type of returned tuple not noted
Expected Behavior
Expected the type of the returned tuple to be noted as 'int' as in definition of the property.
Actual Behavior
Generated documentation notes that the returned data is a tuple, but does not note the type of the data in tuple.
Steps to Reproduce
Ran pdoc3 on file containing above source.
Additional info
- pdoc version: pdoc3 0.9.1 (installed via pip3)
If you look at it closely, it's inserted as sex : (<class 'int'>, <class 'int'>) into HTML, resulting in some invalid HTML.
But I don't think it's a bug necessarily, because the proper way to type-annotate a tuple is with square brackets:
typing.Tuple[int, int] (or tuple[int, int] on Python3.9+).
If you look at it closely, it's inserted as
sex : (<class 'int'>, <class 'int'>)into HTML, resulting in some invalid HTML. But I don't think it's a bug necessarily, because the proper way to type-annotate a tuple is with square brackets:typing.Tuple[int, int](ortuple[int, int]on Python3.9+).
I don't think it's not simply the square brackets, but the relatively new support of built-in types like dict and tuple as type annotation (3.9). Try the following code:
from typing import Dict
import inspect
d1 = Dict[str, int]
d2 = dict[str, int]
print(f'Dict: {inspect.formatannotation(d1)}')
print(f'dict: {inspect.formatannotation(d2)}')
Output:
Dict: Dict[str, int]
dict: dict
I've noticed that several inspect functions are marked as deprecated, especially those beginning with "format". I can't find any official documentation about formatannotations() in the official python documentation, so I'm not sure whether we're supposed to use it...
Output:
Dict: Dict[str, int] dict: dict
This seems to be only a problem with Python 3.9 (maybe 3.8, too). Python 3.10.4 produces correct output:
Dict: Dict[str, int]
dict: dict[str, int]