-
-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Describe the bug
pydantic fields with outer_type (Eg. typing.List
, typing.Set
etc) are populated with the wrong type in documentation. The documentation shows only the inner type. (See example)
To Reproduce
from typing import List, Union
from pydantic import BaseModel, Field
class MyModel(BaseModel):
"""
MyModel
"""
attr_bug: List[str] = Field(..., description="This is a mock attribute that is buggy")
attr_perfect: Union[List[str], List[int]] = Field(description="This is a mock attribute that is perfect")
- The type information of the
attr_bug
shows up asstr
and notList[str]
(which is expected) - The type information of the
attr_perfect
shows up asUnion[List[str], List[int]]
as expected
Expected behavior
Explained above below the code example.
Screenshots
Attaching a screenshot of the documentation produced by mkdocstrings with the above example code
System (please complete the following information):
pytkdocs
version : 0.10.1mkdocstrings
version : 0.14.0- Python version: 3.6.1 (I know I should update!!)
- OS: macOS
Additional context
According to my quick run through the code of pytkdocs
and pydantic
, the reason is most probably because of the below line.
pytkdocs/src/pytkdocs/loader.py
Line 682 in bf04764
attr_type=prop.type_, |
Instead of the above line, it should have been prop.outer_type_
(that is provided by pydantic here).
Debug code
print(MyModel.__dict__["__fields__"]["attr_bug"].type_)
# prints <class 'str'>
print(MyModel.__dict__["__fields__"]["attr_bug"].outer_type_)
# prints typing.List[str]
Lastly, thank you very much for creating mkdocstrings (and pytkdocs)