@@ -262,18 +262,6 @@ class BlackFormatter(Formatter):
262262formatters = {"ruff" : RuffFormatter (), "black" : BlackFormatter ()}
263263
264264
265- def removeprefix (text : str , prefix : str ) -> str :
266- if text .startswith (prefix ):
267- return text [len (prefix ) :]
268- return text
269-
270-
271- def removesuffix (text : str , suffix : str ) -> str :
272- if suffix and text .endswith (suffix ):
273- return text [: - len (suffix )]
274- return text
275-
276-
277265def format_signature (signature : str , config : dict , signature_formatter : str ) -> str :
278266 """Formats signature using ruff or black if either is available."""
279267 as_func = f"def { signature .strip ()} :\n pass"
@@ -282,14 +270,9 @@ def format_signature(signature: str, config: dict, signature_formatter: str) ->
282270 if formatter .is_installed :
283271 try :
284272 return (
285- # TODO: replace with str.removeprefix and str.removesuffix
286- # once Python 3.8 support is no longer required
287- removesuffix (
288- removeprefix (
289- formatter .format (as_func , line_length = line_length ), "def "
290- ),
291- ":\n pass" ,
292- )
273+ formatter .format (as_func , line_length = line_length )
274+ .removeprefix ("def " )
275+ .removesuffix (":\n pass" )
293276 )
294277 except subprocess .CalledProcessError as e :
295278 log .warning ("Signature formatter failed %s" , e )
0 commit comments