aboutsummaryrefslogtreecommitdiffstats
path: root/slack/python_compatibility.py
blob: e96b8afea50f245656f6dedf471fb52e877896d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import traceback
from typing import List


# Copied from https://peps.python.org/pep-0616/ for support for Python < 3.9
def removeprefix(self: str, prefix: str) -> str:
    if self.startswith(prefix):
        return self[len(prefix) :]
    else:
        return self[:]


# Copied from https://peps.python.org/pep-0616/ for support for Python < 3.9
def removesuffix(self: str, suffix: str) -> str:
    if suffix and self.endswith(suffix):
        return self[: -len(suffix)]
    else:
        return self[:]


def format_exception(exc: BaseException) -> List[str]:
    return traceback.format_exception(type(exc), exc, exc.__traceback__)