Skip to content

Commit 0f44fe1

Browse files
committed
Pass options over to _check_ref -> colect
This makes sure the collection function that _check_ref calls will use the appropriate options, rather than the default options. This might be relevant with some configurations, without which collect may fail even if the reference would be correct with the options set.
1 parent b4fa611 commit 0f44fe1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/mkdocstrings_handlers/python_betterrefs/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def render( # pyright: ignore[reportIncompatibleMethodOverride] # we use our ty
5858
options: PythonBetterRefsOptions,
5959
) -> str:
6060
if options.better_crossrefs:
61-
checkref = self._check_ref if options.check_crossrefs else None
61+
checkref = (lambda ref: self._check_ref(ref, options)) if options.check_crossrefs else None
6262
substitute_relative_crossrefs(data, checkref=checkref)
6363

6464
try:
@@ -74,11 +74,11 @@ def get_templates_dir(self, handler: str | None = None) -> Path:
7474
handler = "python"
7575
return super().get_templates_dir(handler)
7676

77-
def _check_ref(self, ref: str) -> bool:
77+
def _check_ref(self, ref: str, options: PythonOptions) -> bool:
7878
"""Check for existence of reference."""
7979
# Try to collect the reference normally and see if it fails
8080
try:
81-
self.collect(ref, PythonOptions())
81+
self.collect(ref, options)
8282
except CollectionError:
8383
return False
8484
else:

tests/test_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def fake_render(_self: PythonHandler, data: CollectorItem, options: PythonOption
315315
monkeypatch.setattr(PythonHandler, "render", fake_render)
316316

317317
# Patch check-ref according to the test parameters
318-
monkeypatch.setattr(PythonBetterRefsHandler, "_check_ref", lambda self, ref: checkref_result)
318+
monkeypatch.setattr(PythonBetterRefsHandler, "_check_ref", lambda self, ref, opts: checkref_result)
319319

320320
# Test if rendering works as expected
321321
rendered = handler.render(griffe_obj, PythonBetterRefsOptions.from_data(**options))

0 commit comments

Comments
 (0)