File: _interface.py

package info (click to toggle)
python-typepy 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: python: 2,886; makefile: 78; sh: 7
file content (29 lines) | stat: -rw-r--r-- 661 bytes parent folder | download | duplicates (2)
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
29
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import abc

from ..error import TypeConversionError


class ValueConverterInterface(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def force_convert(self):  # pragma: no cover
        pass


class AbstractValueConverter(ValueConverterInterface):
    __slots__ = "_value"

    def __init__(self, value, params):
        self._value = value
        self._params = params

    def __repr__(self):
        try:
            string = str(self.force_convert())
        except TypeConversionError:
            string = "[ValueConverter ERROR] failed to force_convert"

        return string