from abc import abstractmethod, ABC
from typing import TypeVar, List

T = TypeVar('T')


class Sanitizer(ABC):

    @abstractmethod
    def _types_to_sanitize(self) -> List[type]:
        return []

    @abstractmethod
    def _sanitize(self, value):
        raise NotImplementedError()

    def sanitize(self, value: T) -> T:
        if type(value) in self._types_to_sanitize():
            return self._sanitize(value)
        return value
