|
12 | 12 |
|
13 | 13 |
|
14 | 14 | def dir_head_adder(
|
15 |
| - qualname_overrides: Mapping[str, str], |
| 15 | + qualname_overrides: Mapping[tuple[str | None, str], tuple[str | None, str]], |
16 | 16 | orig: Callable[[ClassDocumenter, str], None],
|
17 | 17 | ) -> Callable[[ClassDocumenter, str], None]:
|
18 | 18 | @wraps(orig)
|
19 | 19 | def add_directive_header(self: ClassDocumenter, sig: str) -> None:
|
20 | 20 | orig(self, sig)
|
21 |
| - lines: StringList = self.directive.result |
22 |
| - role, direc = ( |
23 |
| - ("exc", "exception") |
| 21 | + lines = self.directive.result |
| 22 | + inferred_role, direc = ( |
| 23 | + ("py:exc", "py:exception") |
24 | 24 | if isinstance(self.object, type) and issubclass(self.object, BaseException)
|
25 |
| - else ("class", "class") |
| 25 | + else ("py:class", "py:class") |
26 | 26 | )
|
27 |
| - for old, new in qualname_overrides.items(): |
| 27 | + for (old_role, old_name), (new_role, new_name) in qualname_overrides.items(): |
| 28 | + role = inferred_role if new_role is None else new_role |
28 | 29 | # Currently, autodoc doesn’t link to bases using :exc:
|
29 |
| - lines.replace(f":class:`{old}`", f":{role}:`{new}`") |
| 30 | + lines.replace( |
| 31 | + f":{old_role or 'py:class'}:`{old_name}`", f":{role}:`{new_name}`" |
| 32 | + ) |
30 | 33 | # But maybe in the future it will
|
31 |
| - lines.replace(f":{role}:`{old}`", f":{role}:`{new}`") |
32 |
| - old_mod, old_cls = old.rsplit(".", 1) |
33 |
| - new_mod, new_cls = new.rsplit(".", 1) |
| 34 | + lines.replace(f":{role}:`{old_name}`", f":{role}:`{new_name}`") |
| 35 | + old_mod, old_cls = old_name.rsplit(".", 1) |
| 36 | + new_mod, new_cls = new_name.rsplit(".", 1) |
34 | 37 | replace_multi_suffix(
|
35 | 38 | lines,
|
36 |
| - (f".. py:{direc}:: {old_cls}", f" :module: {old_mod}"), |
37 |
| - (f".. py:{direc}:: {new_cls}", f" :module: {new_mod}"), |
| 39 | + (f".. {direc}:: {old_cls}", f" :module: {old_mod}"), |
| 40 | + (f".. {direc}:: {new_cls}", f" :module: {new_mod}"), |
38 | 41 | )
|
39 | 42 |
|
40 | 43 | return add_directive_header
|
|
0 commit comments