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 one of the project modules rather than the typing module.
To trigger the issue we need a project where:
there's an autoclass directive for a pydantic model
the model has an annotated field with BeforeValidator/AfterValidator
#src/example/models.py
from typing import Annotated, Any
import pydantic
from . import enumerations
def validate(v: Any) -> Any:
"""
This does nothing but triggers the error.
"""
return v
class CookingModel(pydantic.BaseModel):
fruit: Annotated[enumerations.FruitEnum, pydantic.BeforeValidator(validate)]
# src/example/enumerations.py
from enum import Enum
class FruitEnum(str, Enum):
pear = "pear"
banana = "banana"
With this project structure I'm using a custom extension to find the pending_xref nodes and what I find out is a node with a reftarget equals to example.enumerations.Annotated which is unexpected.
How to Reproduce
I have created a small test repo to illustrate and reproduce the issue.
Describe the bug
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 theAnnotated
class to come from one of the project modules rather than thetyping
module.To trigger the issue we need a project where:
BeforeValidator
/AfterValidator
With this project structure I'm using a custom extension to find the
pending_xref
nodes and what I find out is a node with areftarget
equals toexample.enumerations.Annotated
which is unexpected.How to Reproduce
I have created a small test repo to illustrate and reproduce the issue.
Environment Information
Sphinx extensions
Additional context
No response