Completed
Push — master ( fb6854...6f1632 )
by Ben
01:42
created

Class_Operation.__getattr__()   A

Complexity

Conditions 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
1
class Class_Operation(object):
2
    """
3
    Class Operation
4
    """
5
6
    def __init__(self, operation, cls1, cls2):
7
        """
8
        """
9
        self.cls1 = cls1
10
        self.cls2 = cls2
11
        self._operation = operation
12
13
    def __getattr__(self, attr):
14
        try:
15
            return getattr(getattr(self.cls1, attr),
16
                           self._operation)(getattr(self.cls2, attr))
17
        except AttributeError:
18
            return lambda *args: getattr(
19
                getattr(self.cls1, attr)(*args),
20
                self._operation)(getattr(self.cls2, attr)(*args))
21
22
    def __add__(self, other):
23
        return Class_Operation('__add__', self, other)
24
25
    def __sub__(self, other):
26
        return Class_Operation('__sub__', self, other)
27
28
    def __mul__(self, other):
29
        return Class_Operation('__mul__', self, other)
30
31
    def __gt__(self, other):
32
        return Class_Operation('__gt__', self, other)
33