@@ -301,32 +301,53 @@ def get_serial_pair(serial):
301301 return None , None
302302
303303
304- def remove_prefix (s , prefix ):
304+ @t .overload
305+ def removeprefix (s : str , prefix : str ) -> str : ...
306+
307+
308+ @t .overload
309+ def removeprefix (s : bytes , prefix : bytes ) -> bytes : ...
310+
311+
312+ @t .overload
313+ def removesuffix (s : str , suffix : str ) -> str : ...
314+
315+
316+ @t .overload
317+ def removesuffix (s : bytes , suffix : bytes ) -> bytes : ...
318+
319+
320+ def removeprefix (s , prefix ):
305321 """
306- Remove prefix of a string or bytes like `string.removeprefix(prefix)`, which is on Python3.9+
322+ Backport `string.removeprefix(prefix)`, which is on Python>=3.9
307323
308324 Args:
309- s (str, bytes):
310- prefix (str, bytes):
325+ s (str | bytes):
326+ prefix (str | bytes):
311327
312328 Returns:
313- str, bytes:
329+ str | bytes:
314330 """
315- return s [len (prefix ):] if s .startswith (prefix ) else s
331+ if s .startswith (prefix ):
332+ return s [len (prefix ):]
333+ return s
316334
317335
318- def remove_suffix (s , suffix ):
336+ def removesuffix (s , suffix ):
319337 """
320- Remove suffix of a string or bytes like `string.removesuffix(suffix)`, which is on Python3.9+
338+ Backport `string.removesuffix(suffix)`, which is on Python>=3.9
321339
322340 Args:
323- s (str, bytes):
324- suffix (str, bytes):
341+ s (str | bytes):
342+ suffix (str | bytes):
325343
326344 Returns:
327- str, bytes:
345+ str | bytes:
328346 """
329- return s [:- len (suffix )] if s .endswith (suffix ) else s
347+ # s[:-0] is empty string, so we need to check if suffix is empty
348+ if suffix and s .endswith (suffix ):
349+ return s [:- len (suffix )]
350+ return s
330351
331352
332353class IniterNoMinicap (u2 .init .Initer ):
0 commit comments