@@ -132,24 +132,27 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
132132self.env.filters["crossref"] = self.do_crossref
133133self.env.filters["multi_crossref"] = self.do_multi_crossref
134134self.env.filters["order_members"] = self.do_order_members
135-self.env.filters["format_code"] = self.do_format_code
135+self.env.filters["format_signature"] = self.do_format_signature
136136137-def do_format_code(self, code: str, line_length: int) -> str:
138-"""Format the code using Black.
137+def do_format_signature(self, signature: str, line_length: int) -> str:
138+"""Format a signature using Black.
139139140140 Parameters:
141- code: The code to format.
141+ signature: The signature to format.
142142 line_length: The line length to give to Black.
143143144144 Returns:
145145 The same code, formatted.
146146 """
147147from black import Mode, format_str
148148149-if len(code) >= line_length:
150-mode = Mode(line_length=line_length)
151-return format_str(f"def {code}: pass", mode=mode)[4:-6].strip()
152-return code
149+code = signature.strip()
150+if len(code) < line_length:
151+return code
152+mode = Mode(line_length=line_length)
153+formatted = format_str(f"def {code}: pass", mode=mode)
154+# remove starting `def ` and trailing `: pass`
155+return formatted[4:-5].strip()[:-1]
153156154157def do_order_members(self, members: Sequence[Object | Alias], order: Order) -> Sequence[Object | Alias]:
155158"""Order members given an ordering method.