Skip to content

federicodabrunzo/autodoc-issue-for-pydantic-annotated-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autodoc-issue-for-pydantic-annotated-field

While I was trying to generate documentation with the autodoc extension I came into an issue for certain pydantic models.

It looks like that under certain circumstances autodoc is interpreting the Annotated class to come from a different module as we would expect — for this example its reftarget is example.enumerations.Annotated.

This example project contains the bare minimum to trigger the issue:

  • there's an autoclass directive for a pydantic model
  • the model has an annotated field with BeforeValidator/AfterValidator
  • the annotated type is an enumeration
  • the enumeration is imported from another module

Sphinx is setup with an additional extension that prints the reftarget of pending_xref nodes — in this way we can show the unexpected behavior.

Steps to reproduce

Install the requirements:

pip install -r requirements.txt

Run the build:

sphinx-build --fresh-env docs docs/_build

The output should contain:

===============================
example.enumerations.Annotated
example.enumerations.FruitEnum
pydantic.functional_validators.BeforeValidator
example.models.validate
PydanticUndefined
===============================

The example.enumerations.Annotated line is unexpected.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages