Autodoc - Class attributes required for bases with generic arguments to be resolved when using :show-inheritance:
#13728
Unanswered
tanrbobanr
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Recently, I have been trying to document certain classes that inherit from
pydantic.BaseModel
, but have encountered a bit of an issue. Before I explain, here is some example code:Here is what I would expect when
Derived
is documented:Bases: Base[int, str]
whereBase
references ourBase
class, andint
andstr
reference the pythonint
andstr
classes (via intersphinx).When not using
pydantic.BaseModel
(i.e. just inheriting fromGeneric
), everything works as expected. But when usingpydantic.BaseModel
, a number of odd things happen. First, the reference toBase
fails to be resolved - this is due topydantic
's odd handling of__name__
within__class_get_item__
(the full parametrized name is used, not just the name of the class). If we set__name__
to the actual class name, the reference toBase
is successfully resolved. Unfortunately, this just shines light on another problem - the parameters are now completely ignored bysphinx
(the bases are now shown asBases: Base
). Even thoughBase
inBases
now correctly reference theBase
class, its not really what I'm looking for.This brings me to my question: Which class attributes (or something else) does
sphinx
use to determine the structure ofBases
(particularly bases that are parametrized) when:show-inheritance:
is used? My initial thought was__name__
and__args__
, but manually assigning those to the correct values (in this case"Base"
and(int, str)
respectively) doesn't do the trick.Although at the end of the day it is
pydantic
that is doing something odd with generics, I am still interesting in learning what exactlysphinx
uses to hopefully help me implement a solution.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions