@@ -131,7 +131,9 @@ def read_stable_abi_data(stable_abi_file: Path) -> dict[str, StableABIEntry]:
131131})
132132
133133
134- def read_threadsafety_data (threadsafety_filename : Path ) -> dict [str , ThreadSafetyEntry ]:
134+ def read_threadsafety_data (
135+ threadsafety_filename : Path ,
136+ ) -> dict [str , ThreadSafetyEntry ]:
135137 threadsafety_data = {}
136138 for line in threadsafety_filename .read_text (encoding = "utf8" ).splitlines ():
137139 line = line .strip ()
@@ -301,32 +303,33 @@ def _unstable_api_annotation() -> nodes.admonition:
301303 )
302304
303305
304- _THREADSAFETY_DISPLAY = {
305- "incompatible" : "Not safe to call from multiple threads." ,
306- "compatible" : "Safe to call from multiple threads with external synchronization only." ,
307- "safe" : "Safe for concurrent use." ,
308- }
309-
310- # Maps each thread safety level to the glossary term it should link to.
311- _THREADSAFETY_TERM = {
312- "incompatible" : "thread-incompatible" ,
313- "compatible" : "thread-compatible" ,
314- "safe" : "thread-safe" ,
315- }
316-
317-
318306def _threadsafety_annotation (level : str ) -> nodes .emphasis :
319- display = sphinx_gettext (_THREADSAFETY_DISPLAY [level ])
307+ match level :
308+ case "incompatible" :
309+ display = sphinx_gettext ("Not safe to call from multiple threads." )
310+ reftarget = "thread-incompatible"
311+ case "compatible" :
312+ display = sphinx_gettext (
313+ "Safe to call from multiple threads with external synchronization only."
314+ )
315+ reftarget = "thread-compatible"
316+ case "safe" :
317+ display = sphinx_gettext ("Safe for concurrent use." )
318+ reftarget = "thread-safe"
319+ case _:
320+ raise AssertionError (
321+ "Only the levels 'incompatible', 'compatible' and 'safe' are possible"
322+ )
320323 ref_node = addnodes .pending_xref (
321324 display ,
322325 nodes .Text (display ),
323326 refdomain = "std" ,
324- reftarget = _THREADSAFETY_TERM [ level ] ,
327+ reftarget = reftarget ,
325328 reftype = "term" ,
326329 refexplicit = "True" ,
327330 )
328331 prefix = sphinx_gettext ("Thread safety:" ) + " "
329- classes = [f"threadsafety-{ level } " ]
332+ classes = ["threadsafety" , f"threadsafety-{ level } " ]
330333 return nodes .emphasis ("" , prefix , ref_node , classes = classes )
331334
332335
0 commit comments