-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fallback to return multiple identifiers to try #11
Comments
Oops I thought this was a pull request 😅 |
Thanks! I'll experiment anyway, and send a PR if I get something elegant 🙂 |
Hmm I've certainly never planned for this case, I thought everything should always have unambiguous canonical path. That is, perhaps I straight up disagree with "it should not use the canonical path".
Well no, the returned canonical path should be That's all I have to say for now and probably won't actually be able to look into this in detail. |
Sure, your input is always welcomed 🙂
I thought about it, and yes, perhaps it could use both, which corresponds to the proposed solutions, but not the current situation.
True as well, but considering an object can have multiple aliases, the handler has no way of knowing which one of the aliases the object is registered with. Of course I've very biased toward Python, which certainly does not mirror other languages concepts. But I guess populating the URL map with more data would not be harmful anyway. |
I'm not sure if this is fully true. The handler could perhaps memorize the first identifier it was collected through and use that henceforth. But that would probably be considered more hacky than what you're suggesting.. |
Yeah there are multiple options here! |
Since an object can have aliases (different identifiers leading to it), and since users sometimes want to render an object using one of its aliases instead of its canonical identifier, we make sure to register every identifier associated to an object so that autorefs can find it when fixing cross-references. Issue mkdocstrings/autorefs#11: mkdocstrings/autorefs#11
Issue #11: #11 PR #12: #12 PR mkdocstrings#350: mkdocstrings/mkdocstrings#350
Since an object can have aliases (different identifiers leading to it), and since users sometimes want to render an object using one of its aliases instead of its canonical identifier, we make sure to register every identifier associated to an object so that autorefs can find it when fixing cross-references. Issue mkdocstrings/autorefs#11: mkdocstrings/autorefs#11
Since an object can have aliases (different identifiers leading to it), and since users sometimes want to render an object using one of its aliases instead of its canonical identifier, we make sure to register every identifier associated to an object so that autorefs can find it when fixing cross-references. Issue mkdocstrings/autorefs#11: mkdocstrings/autorefs#11 PR #350: #350
Currently, when autorefs doesn't know the URL for an identifier, it falls back to collecting the object through every handler (and getting an anchor through its renderer) until an anchor is found.
It works well when canonical objects are rendered (the ones with canonical paths, i.e. the identifier corresponding to where they are defined, not imported/aliased), but not the other way around.
Example:
pkg.base
definesClass
pkg
importspkg.base.Class
asClass
pkg.Class
is an alias topkg.base.Class
Class
with its canonical path, autorefs maps its canonical path to its URL[Class][pkg.Class]
crossref, it falls back as mentioned abovepkg.Class
, and returns its canonical path:pkg.base.Class
The other way around:
pkg.base
definesClass
pkg
importpkg.base.Class
asClass
pkg.Class
is an alias topkg.base.Class
Class
with one of its alias path (there could be many), autorefs maps this alias path to its URL (it should not use the canonical path, because the alias is the public one, that's what the user wants)[Class][pkg.base.Class]
(which happens, for example, because of Python annotations that are resolved using their actual scope, which is where they are defined, not imported), it falls back as mentioned abovepkg.base.Class
, and return its canonical path:pkg.base.Class
So, what we need here is one of two things, or both:
Of course if you render the same object, alias or canonical, multiple times, the last iteration wins as it will override mappings in the URL map. But we can consider it an invalid use-case, or a limited one.
The option 2 would also prevent redundant, costly fallbacks. Maybe this can already be improved by updating the URL map when finding a new valid anchor/identifier.
Maybe we could call the renderers
get_anchor[s]
method early, inmkdocstrings.extension.AutodocProcessor.run
andmkdocstrings.extension.AutodocProcessor._process_block
, to register more anchors into autorefs.The text was updated successfully, but these errors were encountered: