Container Types Are Not Rendered Correctly in Documentation
The type annotation for pydantic models are not being rendered correctly in the documentation when using container datatypes.
For example, in nomad/datamodel/metainfo/annotations.py
the lines
property of the PlotAnnotation
class is documented as:
lines: List[dict] = Field(None, description='''
A list of dicts passed as `traces` to plotly to configure the lines of the plot.
See [https://plotly.com/javascript/reference/scatter/](https://plotly.com/javascript/reference/scatter/) for details.
''')
But in the documentation it is being rendered as:
The problem seems to be in nomad/mkdocs.py
in the function field_row()
:
def field_row(field):
if field.name.startswith('m_'):
return ''
type_ = field.type_
if isclass(type_) and issubclass(type_, config.NomadSettings):
required_models.add(type_)
try:
type_name = type_.__name__
except Exception:
type_name = str(type_)
return f'|{field.name}|{type_name}|{content(field)}|\n'
It doesn't seem like type_.__name__
is a good string representation. The private method _type_display()
of the pydantic.field.ModelField
class gives a nice string but is unfortunately private. It's being called in ModelField
s __repr_args__
though so maybe we can use it somehow. As an example the docs above show the following if type_name = field._type_display()
: