@@ -169,6 +169,18 @@ def format_internal_tuple(t: tuple[Any, ...], config: Config) -> str:
169
169
return f"({ ', ' .join (fmt )} )"
170
170
171
171
172
+ def fixup_module_name (config : Config , module : str ) -> str :
173
+ if getattr (config , "typehints_fixup_module_name" , None ):
174
+ module = config .typehints_fixup_module_name (module )
175
+
176
+ if module == "typing_extensions" :
177
+ module = "typing"
178
+
179
+ if module == "_io" :
180
+ module = "io"
181
+ return module
182
+
183
+
172
184
def format_annotation (annotation : Any , config : Config ) -> str : # noqa: C901, PLR0911, PLR0912, PLR0915, PLR0914
173
185
"""
174
186
Format the annotation.
@@ -204,13 +216,7 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901, PL
204
216
except ValueError :
205
217
return str (annotation ).strip ("'" )
206
218
207
- # Redirect all typing_extensions types to the stdlib typing module
208
- if module == "typing_extensions" :
209
- module = "typing"
210
-
211
- if module == "_io" :
212
- module = "io"
213
-
219
+ module = fixup_module_name (config , module )
214
220
full_name = f"{ module } .{ class_name } " if module != "builtins" else class_name
215
221
fully_qualified : bool = getattr (config , "typehints_fully_qualified" , False )
216
222
prefix = "" if fully_qualified or full_name == class_name else "~"
@@ -967,6 +973,7 @@ def setup(app: Sphinx) -> dict[str, bool]:
967
973
app .add_config_value ("typehints_formatter" , None , "env" )
968
974
app .add_config_value ("typehints_use_signature" , False , "env" ) # noqa: FBT003
969
975
app .add_config_value ("typehints_use_signature_return" , False , "env" ) # noqa: FBT003
976
+ app .add_config_value ("typehints_fixup_module_name" , None , "env" )
970
977
app .add_role ("sphinx_autodoc_typehints_type" , sphinx_autodoc_typehints_type_role )
971
978
app .connect ("env-before-read-docs" , validate_config ) # config may be changed after “config-inited” event
972
979
app .connect ("autodoc-process-signature" , process_signature )
0 commit comments