Passed
Push — dev ( 3c73d5...40dcc8 )
by Konstantinos
01:24
created

ominal_encoder()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
import abc
2
from abc import ABC
3
4
5
class EncoderInterface(abc.ABC):
6
    @abc.abstractmethod
7
    def encode(self, *args, **kwargs):
8
        raise NotImplementedError
9
10
class AbstractEncoder(EncoderInterface):
11
    @abc.abstractmethod
12
    def encode(self, *args, **kwargs):
13
        raise NotImplementedError
14
15
16
class Encoder(AbstractEncoder, ABC):
17
    subclasses = {}
18
19
    @classmethod
20
    def register_as_subclass(cls, backend_type):
21
        def wrapper(subclass):
22
            cls.subclasses[backend_type] = subclass
23
            return subclass
24
        return wrapper
25
26
    @classmethod
27
    def create(cls, backend_type, *args, **kwargs):
28
        if backend_type not in cls.subclasses:
29
            raise ValueError('Bad "BinnerFactory Backend type" type \'{}\''.format(backend_type))
30
        return cls.subclasses[backend_type](*args, **kwargs)
31