Skip to content

Conversation

@Bibo-Joshi
Copy link
Contributor

Spin-off of #13: Better support for nitpicky mode.

Currently, :paramref: is resolved without checking if the resulting target exists. By checking against the index created in build_index within lookup_params and returning None if the target doesn't exist, we give sphinx a chance to emit a warning about an unresolved reference, if needed. This minimal-effort approach has two downsides:

First, the _sphinx_paramlinks_ prefix is still included in the warning, e.g.

path\to\python-telegram-bot\telegram\ext\_basepersistence.py:docstring of telegram.ext._basepersistence.BasePersistence.insert_bot:1: WARNING: py:paramref reference target not found: _sphinx_paramlinks_bot

Secondly, I don't know how well it plays with the nitpick_ignore and nitpick_ignore_regex settings (I guess the prefix could mean trouble here)

Alternatively, one could add an event handler for the warn-missing-reference event, but the built-in logic for that is actually somewhat elaborate. At least for me, adapting this for sphinx-paramlinks is not worth the effort - I can live with the prefix and so far I don't use the nitpick_ignore settings

@Bibo-Joshi Bibo-Joshi mentioned this pull request Dec 1, 2021
# Conflicts:
#	sphinx_paramlinks/sphinx_paramlinks.py
@Bibo-Joshi
Copy link
Contributor Author

Hi. May I kindly ping on this? If you anticipate that reviewing this PR won't happen in the near future, that's ofc understandable - would just be convenient to know since I have a PR open that could proceed differently in that case :)

@zzzeek
Copy link
Contributor

zzzeek commented Jan 18, 2022

hey there -

yes sorry, i have lots and lots going on and this particular PR, I'd have to spend time with to understand the implications. in particular if it's going to change when/if/how errors or warnings are getting reported, that may or may not be trouble. as you mention, we dont know how it will interact with nitpick_ignore, and I dont have a good understanding of sphinx's various "nitpicky" modes in any case they seem to have changed from what they were a long time ago.

might it be simpler for sphinx-paramlinks itself to just emit a warning, but otherwise not change in any behavioral sense ?

@Bibo-Joshi
Copy link
Contributor Author

No worries.

I understand your concerns and your message lead me to have another look at the internals of sphinx. Indeed I had misunderstood the situation a bit. The flow is as follows:

  1. sphinx encounters a reference that wasn't resolved
  2. pass it to the missing-reference handlers (lookup_params in case of sphinx-pl) - if one of them returns a node, the reference is maked as resolved.
  3. if instead all handlers returned None:
  4. first check if it's supposed to be ignored by the nitpick_ignore(_regex) settings. this works with the node["reftarget"], for which sphinx-pl inserts the _sphinx_paramlinks_ marker
  5. if not, forward it to the warn-missing-reference handlers. if none of them returns True, issue a default warning.

So by returning None from lookup_params, we'd already have proper nitpick support - with the caveat that one needs to ignore ('py:paramref', '_sphinx_paramlinks_current_offset') rather than ('py:paramref', 'current_offset') and similar for the regex.

Implementing a handler for warn-missing-reference or issuing the warning directly in lookup_params would have the upside that the proper name can be shown in the log entry and it would allow to apply adjusted handling for nitpicky settings. The downside would be additional implementation effort, especially if the nitpicky settings should be respected.


The punchlin(s) is

  • by returning None from lookup_params, nitpick_ignore is applied to sphinx-pl out of the box
  • to use it, one either needs custom tooling in sphinx-pl or needs to remember the _sphinx_paramlinks_ marker for the nitpicky_ignore settings.

Personally, I'd be fine without custom tooling and just documenting the limitation.

@zzzeek
Copy link
Contributor

zzzeek commented Aug 11, 2023

looks like a doc fix was made upstream so that I dont have to try to understand waht this is about, thanks!

@zzzeek zzzeek closed this Aug 11, 2023
@Bibo-Joshi
Copy link
Contributor Author

Hi. Unfortunately sphinx-doc/sphinx#10119 does not actually resolve this PR, but is just a spin-off documentation fix that I noticed while working on this one. What this PR addresses is the 2nd point in my comment #14 (comment). What sphinx-doc/sphinx#10119 does is clarify point 4 inside the sphinx docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants