Hello, I think this is a bug (not recursively resolved maybe?).
I will give two code snippets for minimal reproducers and at the very bottom is the rst code and relevant conf.py configuration (I tried with all defaults, still the same as well). My environment:
python 3.11
sphinx 7.2.6
myst-parser 2.0.0 (irrelevant to this but adding in case)
autodoc-pydantic 2.0.1
Standard Python Classes
from typing import TypeAlias
class BaseClassA:
"""Base-class A."""
class BaseClassB:
"""Base-class B."""
compound_type: TypeAlias = BaseClassA | BaseClassB
class SomeOther:
"""Some other class.
Attributes:
a: is a
b: is b
c: is c
"""
a: BaseClassA
b: BaseClassB
c: compound_type | None
class SubClassSomeOther(SomeOther):
"""Subclass of some other.
Attributes:
a: is a
b: is b
c: is c
d: is d
"""
d: int | None = None
As you can see, the type hints get unfolded (as expected) and propagate down to SubClassSomeOther.
Pydantic Models
from pydantic import Field, BaseModel
class PydanticBaseClassA(BaseModel):
"""Base-model A."""
class PydanticBaseClassB(BaseModel):
"""Base-model B."""
pydantic_compound_type: TypeAlias = PydanticBaseClassA | PydanticBaseClassB
class PydanticSomeOther(BaseModel):
"""Some other model."""
a: PydanticBaseClassA = Field(..., description="is a")
b: PydanticBaseClassB = Field(..., description="is b")
c: pydantic_compound_type = Field(..., description="is c")
class PydanticSubClassSomeOther(PydanticSomeOther):
"""Subclass of some other model."""
d: int | None = Field(default=None, description="is d")
As you will see below, after subclassing PydanticSomeOther as PydanticSubClassSomeOther we lost the unfolding and now our documentation doesn't know what pydantic_compound_type is.
Hello, I think this is a bug (not recursively resolved maybe?).
I will give two code snippets for minimal reproducers and at the very bottom is the
rst
code and relevantconf.py
configuration (I tried with all defaults, still the same as well). My environment:python
3.11sphinx
7.2.6myst-parser
2.0.0 (irrelevant to this but adding in case)autodoc-pydantic
2.0.1Standard Python Classes
As you can see, the type hints get unfolded (as expected) and propagate down to
SubClassSomeOther
.Pydantic Models
As you will see below, after subclassing
PydanticSomeOther
asPydanticSubClassSomeOther
we lost the unfolding and now our documentation doesn't know whatpydantic_compound_type
is.Sphinx
rst
andconf.py