@@ -279,6 +279,55 @@ def __init__(self):
279279 assert targets == (["str" ] if signature_crossrefs else [])
280280
281281
282+ @pytest .mark .skipif (sys .version_info < (3 , 12 ), reason = "requires PEP 695 syntax" )
283+ @pytest .mark .parametrize ("mkdocs_conf" , [{"theme" : "material" }, {"theme" : "readthedocs" }], indirect = True )
284+ @pytest .mark .parametrize ("separate_signature" , [False , True ])
285+ @pytest .mark .parametrize ("show_type_parameters" , [False , True ])
286+ @pytest .mark .parametrize ("merge_init" , [False , True ])
287+ def test_class_signature_type_parameters (
288+ handler : PythonHandler ,
289+ separate_signature : bool ,
290+ show_type_parameters : bool ,
291+ merge_init : bool ,
292+ ) -> None :
293+ """Show class type parameters with or without a merged constructor."""
294+ code = """
295+ class Box[T]:
296+ pass
297+
298+ class Pair[T]:
299+ def __init__(self, first: T, second: T):
300+ pass
301+ """
302+ options = handler .get_options (
303+ {
304+ "merge_init_into_class" : merge_init ,
305+ "separate_signature" : separate_signature ,
306+ "show_root_full_path" : False ,
307+ "show_root_heading" : True ,
308+ "show_signature_type_parameters" : show_type_parameters ,
309+ "show_source" : False ,
310+ },
311+ )
312+ selector = ".doc-signature" if separate_signature else ".doc-heading"
313+ type_parameters = "[T]" if show_type_parameters else ""
314+ with temporary_visited_module (code ) as module :
315+ box_html = bs4 .BeautifulSoup (handler .render (module ["Box" ], options ), "html.parser" )
316+ pair_html = bs4 .BeautifulSoup (handler .render (module ["Pair" ], options ), "html.parser" )
317+
318+ box_signature = box_html .select_one (selector )
319+ pair_signature = pair_html .select_one (selector )
320+ for name , signature , constructor in (
321+ ("Box" , box_signature , "" ),
322+ ("Pair" , pair_signature , "(first,second)" if merge_init else "" ),
323+ ):
324+ if separate_signature and not (show_type_parameters or constructor ):
325+ assert signature is None
326+ else :
327+ assert signature is not None
328+ assert signature .get_text (strip = True ) == f"{ name } { type_parameters } { constructor } "
329+
330+
282331@pytest .mark .parametrize (
283332 ("handler" , "merge_init_into_class" ),
284333 [
0 commit comments