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
Derivedis documented:Bases: Base[int, str]whereBasereferences ourBaseclass, andintandstrreference the pythonintandstrclasses (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 toBasefails 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 toBaseis 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 thoughBaseinBasesnow correctly reference theBaseclass, its not really what I'm looking for.This brings me to my question: Which class attributes (or something else) does
sphinxuse 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
pydanticthat is doing something odd with generics, I am still interesting in learning what exactlysphinxuses to hopefully help me implement a solution.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions