pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

Type of returned tuple not noted

Open mlongval opened this issue 4 years ago • 3 comments

Screen Shot 2020-11-03 at 2 12 42 PM

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)

mlongval avatar Nov 03 '20 19:11 mlongval

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+).

kernc avatar Nov 03 '20 20:11 kernc

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+).

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...

frank101010 avatar Apr 06 '22 14:04 frank101010

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]

frank101010 avatar Apr 06 '22 15:04 frank101010