Skip to content

Commit 647afb5

Browse files
committed
fix: Fix normalization of extension paths on the annoying operating system and Python 3.13
Python 3.13 changed `os.path.isabs`: > On Windows, `isabs()` no longer considers paths starting with exactly one slash (`\` or `/`) to be absolute. See https://docs.python.org/3/whatsnew/3.13.html#os-path.
1 parent 6c5b5c3 commit 647afb5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/mkdocstrings_handlers/python/handler.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,9 @@ def normalize_extension_paths(self, extensions: Sequence) -> Sequence:
469469
pth = str(ext)
470470
options = None
471471

472-
if pth.endswith(".py") or ".py:" in pth or "/" in pth or "\\" in pth: # noqa: SIM102
473-
# This is a sytem path. Normalize it.
474-
if not os.path.isabs(pth):
475-
# Make path absolute relative to config file path.
476-
pth = os.path.normpath(os.path.join(base_path, pth))
472+
if pth.endswith(".py") or ".py:" in pth or "/" in pth or "\\" in pth:
473+
# This is a system path. Normalize it, make it absolute relative to config file path.
474+
pth = os.path.abspath(os.path.join(base_path, pth))
477475

478476
if options is not None:
479477
normalized.append({pth: options})

tests/test_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def test_extension_paths(tmp_path: Path, expect_change: bool, extension: str | d
138138
normalized = handler.normalize_extension_paths([extension])[0]
139139
if expect_change:
140140
if isinstance(normalized, str) and isinstance(extension, str):
141-
assert normalized == str(tmp_path.joinpath(extension))
141+
assert normalized == os.fspath(tmp_path.joinpath(extension))
142142
elif isinstance(normalized, dict) and isinstance(extension, dict):
143143
pth, options = next(iter(extension.items()))
144-
assert normalized == {str(tmp_path.joinpath(pth)): options}
144+
assert normalized == {os.fspath(tmp_path.joinpath(pth)): options}
145145
else:
146146
raise ValueError("Normalization must not change extension items type")
147147
else:

0 commit comments

Comments
 (0)