First of all, thanks for developing pytkdocs!
I do not use pytkdocs directly, but rather mkdocs and mkdocstrings which call pytkdocs.
Here is an example for reproduction.
import pandera as pa
from pandera.typing import DataFrame
from pandera.typing import Series
class Foo(pa.DataFrameModel):
"""
Some description
"""
bar: Series[int]
cause_error = DataFrame[Foo]({"bar": [1,2,3]})
Without any instantiated code (that actually uses the panderas models) it runs just fine. But, as soon as I USE the models somewhere in some precomputed objects pytkdocs runs into the following errors:
ERROR - mkdocstrings: 'tuple' object has no attribute 'required'
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/cli.py", line 205, in main
output = json.dumps(process_json(line))
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/cli.py", line 114, in process_json
return process_config(json.loads(json_input))
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/cli.py", line 91, in process_config
obj = loader.get_object_documentation(path, members)
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/loader.py", line 358, in get_object_documentation
root_object = self.get_module_documentation(leaf, members)
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/loader.py", line 426, in get_module_documentation
root_object.add_child(self.get_class_documentation(child_node))
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/loader.py", line 544, in get_class_documentation
self.add_fields(
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/loader.py", line 612, in add_fields
root_object.add_child(add_method(child_node))
File "/usr/local/lib/python3.10/dist-packages/pytkdocs/loader.py", line 712, in get_pydantic_field_documentation
if prop.required:
AttributeError: 'tuple' object has no attribute 'required'
It seems these pandera models are detected as pydantic, but they do not have the same attributes.
For proper pydantic classes we have this:
from pydantic import BaseModel
class Test(BaseModel):
i: int
Test.__fields__["i"]
# yields True
For pandera models we seem to have this
import pandera as pa
from pandera.typing import Series
from pandera.typing import DataFrame
class Foo(pa.DataFrameModel):
bar: Series[int]
Foo.__fields__
# is {}
foo = DataFrame[Foo]({"bar": [1,2,3]})
# after instantiating things exist and probably that's why it causes errors in pytkdocs
Foo.__fields__["bar"]
# <pandera.typing.common.AnnotationInfo at 0x7f...>, <pandera.api.pandas.model_components.FieldInfo("bar") object at 0x7f1...>)
pytkdocs 0.16.1, python 3.10.7, Linux
pydantic 1.10.11 with pydantic_core 2.1.2 (pandera imposes a restriction of pydantic <2)
pandera 0.15.2
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too