Skip to content

Commit 554a0c4

Browse files
authored
🐛 fix(intersphinx): exclude builtin type aliases from mapping (#650)
When `docs.python.org` is configured as an intersphinx mapping, `dict` types get incorrectly resolved as `wsgiref.types.WSGIEnvironment`. This happens because `WSGIEnvironment` is a type alias for `dict[str, Any]`, and at runtime its `__module__.__qualname__` resolves to `builtins.dict` — which the mapping then records as a remapping target. The root cause is that bare inventory names like `dict`, `int`, `str` have no module prefix, so `rpartition(".")` yields an empty module path and skips resolution entirely. This meant `builtins.dict` never entered the exclusion set, allowing type aliases that resolve to builtins to incorrectly claim the mapping. The fix adds `builtins.{name}` to the exclusion set for all bare inventory names, ensuring type aliases pointing to builtins are filtered out. Fixes #649
1 parent bcd118f commit 554a0c4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/sphinx_autodoc_typehints/_intersphinx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def build_type_mapping(env: BuildEnvironment) -> dict[str, str]:
2727
all_documented.add(documented_name)
2828
mod_path, _, attr_name = documented_name.rpartition(".")
2929
if not mod_path:
30+
all_documented.add(f"builtins.{documented_name}")
3031
continue
3132
try:
3233
mod = importlib.import_module(mod_path)

tests/test_intersphinx_mapping.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def test_build_type_mapping_multiple_roles() -> None:
8585
assert result["_thread._local"] == "threading.local"
8686

8787

88+
def test_build_type_mapping_skips_builtin_alias() -> None:
89+
inventory_data: dict[str, dict[str, Any]] = {
90+
"py:class": {
91+
"dict": ("", "", "", ""),
92+
"wsgiref.types.WSGIEnvironment": ("", "", "", ""),
93+
},
94+
}
95+
result = build_type_mapping(_make_env(inventory_data))
96+
assert "builtins.dict" not in result
97+
98+
8899
def test_format_annotation_applies_intersphinx_mapping() -> None:
89100
conf = create_autospec(
90101
Config,

0 commit comments

Comments
 (0)