• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CityOfZion / neo3-boa / e084b44c-1a5f-4649-92cd-d3ed06099181

05 Mar 2024 05:58PM UTC coverage: 92.023% (-0.08%) from 92.107%
e084b44c-1a5f-4649-92cd-d3ed06099181

push

circleci

Mirella de Medeiros
CU-86drpnc9z - Drop support to Python 3.10

20547 of 22328 relevant lines covered (92.02%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/boa3/internal/model/operation/binary/binaryoperation.py
1
from __future__ import annotations
2✔
2

3
from abc import ABC, abstractmethod
2✔
4

5
from boa3.internal.model.operation.operation import IOperation
2✔
6
from boa3.internal.model.type.itype import IType
2✔
7

8

9
class BinaryOperation(IOperation, ABC):
2✔
10
    """
11
    An interface used to represent binary operations
12

13
    :ivar operator: the operator of the operation. Inherited from :class:`IOperation`
14
    :ivar left: the left operand type. Inherited from :class:`BinaryOperation`
15
    :ivar right: the left operand type. Inherited from :class:`BinaryOperation`
16
    :ivar result: the result type of the operation.  Inherited from :class:`IOperation`
17
    """
18
    _valid_types: list[IType] = []
2✔
19

20
    def __init__(self, left: IType, right: IType = None):
2✔
21
        if right is None:
2✔
22
            right = left
2✔
23

24
        self.left_type: IType = left
2✔
25
        self.right_type: IType = right
2✔
26
        result = self._get_result(left, right)
2✔
27
        super().__init__(self.operator, result)
2✔
28

29
    @property
2✔
30
    def number_of_operands(self) -> int:
2✔
31
        return 2
2✔
32

33
    @property
2✔
34
    def is_symmetric(self) -> bool:
2✔
35
        return False
2✔
36

37
    @abstractmethod
2✔
38
    def _get_result(self, left: IType, right: IType) -> IType:
2✔
39
        """
40
        Gets the result type of the operation given the operands types.
41

42
        :param left: left operand type
43
        :param right: right operand type
44
        :return: the result type of the operation. Type.none if the operands are not valid.
45
        """
46
        pass
×
47

48
    @classmethod
2✔
49
    def build(cls, *operands: IType) -> BinaryOperation | None:
2✔
50
        if len(operands) == 1:
2✔
51
            return cls._build_with_left_arg(operands[0])
×
52
        if len(operands) == 2:
2✔
53
            return cls._build_with_two_args(operands[0], operands[1])
2✔
54

55
    @classmethod
2✔
56
    def _build_with_left_arg(cls, left: IType) -> BinaryOperation | None:
2✔
57
        """
58
        Creates a binary operation with the given operands types
59

60
        :param left: left operand type
61
        :return: The built operation if the operands is valid. None otherwise
62
        :rtype: BinaryOperation or None
63
        """
64
        return cls(left)
×
65

66
    @classmethod
2✔
67
    def _build_with_two_args(cls, left: IType, right: IType) -> BinaryOperation | None:
2✔
68
        """
69
        Creates a binary operation with the given operands types
70

71
        :param left: left operand type
72
        :param right: right operand type
73
        :return: The built operation if the operands are valid. None otherwise
74
        :rtype: BinaryOperation or None
75
        """
76
        operation = cls(left, right)
2✔
77
        if operation.validate_type(left, right):
2✔
78
            return operation
2✔
79
        return cls(left, left)
2✔
80

81
    def get_valid_operand_for_validation(self, left_operand: IType,
2✔
82
                                         right_operand: IType = None) -> tuple[IType | None, IType | None]:
83
        """
84
        Returns a valid operand type for the given types.
85

86
        :param left_operand: reference type
87
        :param right_operand: reference type
88
        """
89
        return next((valid_type for valid_type in self._valid_types if valid_type.is_type_of(left_operand)),
2✔
90
                    None), self.right_type
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc