You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
fromtypingimportList, UnionfrompydanticimportBaseModel, FieldclassMyModel(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 as str and not List[str] (which is expected)
The type information of the attr_perfect shows up as Union[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.1
mkdocstrings 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.
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)
The text was updated successfully, but these errors were encountered:
Change `prop.type_` to `prop.outer_type_` to get the
correct type of the pydantic field when using List/Set/Tuple/Union
Optional[Type] does not work because of pydantic's internal
implementation to change outer_type
Fixesmkdocstrings#94
Change `prop.type_` to `prop.outer_type_` to get the
correct type of the pydantic field when using List/Set/Tuple/Union
Optional[Type] does not work because of pydantic's internal
implementation to change outer_type
Fixesmkdocstrings#94
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
attr_bug
shows up asstr
and notList[str]
(which is expected)attr_perfect
shows up asUnion[List[str], List[int]]
as expectedExpected 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.0Additional context
According to my quick run through the code of
pytkdocs
andpydantic
, the reason is most probably because of the below line.pytkdocs/src/pytkdocs/loader.py
Line 682 in bf04764
Instead of the above line, it should have been
prop.outer_type_
(that is provided by pydantic here).Debug code
Lastly, thank you very much for creating mkdocstrings (and pytkdocs)
The text was updated successfully, but these errors were encountered: