@@ -262,18 +262,6 @@ class BlackFormatter(Formatter):
262
262
formatters = {"ruff" : RuffFormatter (), "black" : BlackFormatter ()}
263
263
264
264
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
-
277
265
def format_signature (signature : str , config : dict , signature_formatter : str ) -> str :
278
266
"""Formats signature using ruff or black if either is available."""
279
267
as_func = f"def { signature .strip ()} :\n pass"
@@ -282,14 +270,9 @@ def format_signature(signature: str, config: dict, signature_formatter: str) ->
282
270
if formatter .is_installed :
283
271
try :
284
272
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" )
293
276
)
294
277
except subprocess .CalledProcessError as e :
295
278
log .warning ("Signature formatter failed %s" , e )
0 commit comments