zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Python3.9 introduces removesuffix and remove prefix.
 
They're reimplemented here for use in Python3.8.
 
NOTE: when pyupgrade --py39-plus removes nearly everything in this file,
this file and the associated tests should be removed.
"""
from __future__ import annotations
 
import sys
 
if sys.version_info < (3, 9):
 
    def removesuffix(string: str, suffix: str) -> str:
        if string.endswith(suffix):
            return string[: -len(suffix)]
        return string
 
    def removeprefix(string: str, prefix: str) -> str:
        if string.startswith(prefix):
            return string[len(prefix) :]
        return string
 
else:
    # NOTE: remove this file when pyupgrade --py39-plus removes
    # the above block
    pass