You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: “type”, not “typealias“ & you’re confusing “role” and “objtype” #339
Thanks for the report @flying-sheep. Can you link to Sphinx's documentation about this? I find their docs extremely poor on the subject.
From what I was able to gather, here's the complete list of roles we can use in objects.inv:
mod
func
deco
data
const
class
meth
attr
type
exc
obj
Here's what we're writing from mkdocstrings-python:
module (wrong, should be mod)
function (wrong, should func/deco/meth)
data (right)
class (right)
attr (right)
typealias (wrong, should be type)
param (no equivalent)
typeparam (no equivalent) @bskinn you might find this interesting. Could be nice if sphobjinv would explicitly list those roles, at least for the py domain 🙂
@flying-sheep as you can see Sphinx doesn't even allow registering entries for parameters (or type parameters) so I had to take some liberties there... 😅
What we never write from mkdocstrings-python:
const: hard to distinguish from data/attr when iterating on extracted API data
exc: could be relatively easy to use it on classes that inherit from Exception or BaseException
obj: maybe we should use that one instead of the unsupported "param" and "typeparam"...
The catch with surfacing these in sphobjinv runtime use is that, as best I recall, it would require including Sphinx as a full dependency, which I would prefer not to do (at least, not in the core dependencies) given its size.
It might work to place this sort of functionality behind an extra/optional-dependency, though ... that way, an end-user would have the choice to install a heavier dependency set if they want the functionality.
The catch with surfacing these in sphobjinv runtime use is that, as best I recall, it would require including Sphinx as a full dependency, which I would prefer not to do (at least, not in the core dependencies) given its size.
Understandable. As mentioned in https://github.com/orgs/sphinx-doc/discussions/12204 though, the object types haven't changed for a long time, so maybe a static table (no need to depend on Sphinx) in sphobjinv's docs with a little warning about it possibly going stale could still be valuable, to make it clear what object types are valid in the inventory (no need to document roles/directives equivalents).
New object types get added at the frequency that Python adds them, so very slowly. I think it’s very feasible to hardcode them all (with a comment that the source of truth is intersphinx, and sphobjinv is a useful 3rd party resource dealing with the same problem)
classmethod, staticmethod (can easily fix, not sure it's worth)
Hmm, I don’t think I’ve ever seen these. Worth double checking if these get emitted.
Yes, good idea, I started vibe-coding a script yesterday to analyze the top N Python packages to see some stats. Here they are for the top 500 packages (for those we could find an inventory for).
Object types by inventory count (number of projects, not occurrences):
@bskinn what do you think of renaming the "role" field to "object type" in sphobjinv's docs, in addition to listing the valid object types (without a runtime dependency on Sphinx)? I can send a PR if you want 🙂
Thinking about it, "object type" is not exactly the most generic field name. Works for Python, but might not work for many other domains that aren't about programming languages. Even for Python, if Sphinx ever adds support for parameters, "object" doesn't fit a parameter. Even "symbol" wouldn't fit 🤔 So maybe just "type"?
I merged #340, mkdocstrings-python will now correctly use attribute instead of attr, and type instead of typealias. We still use non-builtin types such as parameter and typeparameter, because to me it looks like this is a valid use-case: the domain object types are public API in Sphinx.
Activity
pawamoy commentedon Sep 3, 2026
Thanks for the report @flying-sheep. Can you link to Sphinx's documentation about this? I find their docs extremely poor on the subject.
From what I was able to gather, here's the complete list of roles we can use in objects.inv:
Here's what we're writing from mkdocstrings-python:
@bskinn you might find this interesting. Could be nice if sphobjinv would explicitly list those roles, at least for the
pydomain 🙂@flying-sheep as you can see Sphinx doesn't even allow registering entries for parameters (or type parameters) so I had to take some liberties there... 😅
What we never write from mkdocstrings-python:
ExceptionorBaseExceptionpawamoy commentedon Sep 3, 2026
Well, no, looks like I got this backwards. So we're mostly good except for
attrinstead ofattribute?pawamoy commentedon Sep 3, 2026
So, valid object types (or "roles" as defined by sphobjinv):
WDYT @flying-sheep 🙂?
bskinn commentedon Sep 3, 2026
@pawamoy There has been some discussion along these lines in bskinn/sphobjinv#234, though with a different focus. OP there already did some forensics that might be helpful; e.g., at bskinn/sphobjinv#234 (comment)
bskinn commentedon Sep 3, 2026
The catch with surfacing these in
sphobjinvruntime use is that, as best I recall, it would require including Sphinx as a full dependency, which I would prefer not to do (at least, not in the core dependencies) given its size.It might work to place this sort of functionality behind an extra/optional-dependency, though ... that way, an end-user would have the choice to install a heavier dependency set if they want the functionality.
pawamoy commentedon Sep 3, 2026
Understandable. As mentioned in https://github.com/orgs/sphinx-doc/discussions/12204 though, the object types haven't changed for a long time, so maybe a static table (no need to depend on Sphinx) in sphobjinv's docs with a little warning about it possibly going stale could still be valuable, to make it clear what object types are valid in the inventory (no need to document roles/directives equivalents).
flying-sheep commentedon Sep 4, 2026
New object types get added at the frequency that Python adds them, so very slowly. I think it’s very feasible to hardcode them all (with a comment that the source of truth is intersphinx, and sphobjinv is a useful 3rd party resource dealing with the same problem)
Hmm, I don’t think I’ve ever seen these. Worth double checking if these get emitted.
flying-sheep commentedon Sep 4, 2026
here are the stats from my projects (inflated by duplicate inventories). Notable:
parameteris emitted from docstring parsing, not the AST, so maybe out of scope for a bugfix, but definitely a worthy featuretypealiascomes from you of course, this is what this issue is aboutpawamoy commentedon Sep 4, 2026
Yes, good idea, I started vibe-coding a script yesterday to analyze the top N Python packages to see some stats. Here they are for the top 500 packages (for those we could find an inventory for).
Object types by inventory count (number of projects, not occurrences):
Invalid object types by builder:
Valid object types by total occurrence count:
Invalid object types by total occurrence count:
Looks like some Sphinx projects are taking some liberties with their objects inventory too.
pawamoy commentedon Sep 4, 2026
@bskinn what do you think of renaming the "role" field to "object type" in sphobjinv's docs, in addition to listing the valid object types (without a runtime dependency on Sphinx)? I can send a PR if you want 🙂
pawamoy commentedon Sep 4, 2026
Thinking about it, "object type" is not exactly the most generic field name. Works for Python, but might not work for many other domains that aren't about programming languages. Even for Python, if Sphinx ever adds support for parameters, "object" doesn't fit a parameter. Even "symbol" wouldn't fit 🤔 So maybe just "type"?
flying-sheep commentedon Sep 4, 2026
Yeah, some extensions:
sphinx_toolbox.more_autodocinventspy:enumandpy:protocolsphinx-immaterialandsphinx-paramlinksinventpy:parameterSphinx already has documents and sections in the inventory, and all of these have “objtypes”: https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/intersphinx/_resolve.py#L144
pawamoy commentedon Sep 4, 2026
Yeah, maybe lets not argue about their naming choices and just stay close to their implementation. It's an "object" inventory after all.
pawamoy commentedon Sep 4, 2026
Opened a discussion there btw: https://github.com/orgs/sphinx-doc/discussions/14667.
fix: Improve inventory object types (incorrectly called roles in mkdo…
pawamoy commentedon Sep 22, 2026
I merged #340, mkdocstrings-python will now correctly use
attributeinstead ofattr, andtypeinstead oftypealias. We still use non-builtin types such asparameterandtypeparameter, because to me it looks like this is a valid use-case: the domain object types are public API in Sphinx.