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

CityOfZion / neo3-boa / 0aff654d-b027-49a1-9d97-558d9a2a52ff

05 Mar 2024 04:57PM UTC coverage: 91.985% (-0.1%) from 92.106%
0aff654d-b027-49a1-9d97-558d9a2a52ff

push

circleci

web-flow
Merge pull request #1215 from CityOfZion/CU-86drpndkk

CU-86drpndkk - Refactor test_interop/test_blockchain.py to use BoaTestConstructor

1 of 1 new or added line in 1 file covered. (100.0%)

658 existing lines in 143 files now uncovered.

20635 of 22433 relevant lines covered (91.99%)

1.84 hits per line

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

97.14
/boa3/internal/model/type/annotation/optionaltype.py
1
from collections.abc import Iterable
2✔
2
from typing import Any
2✔
3

4
from boa3.internal.model.type.annotation.uniontype import UnionType
2✔
5
from boa3.internal.model.type.itype import IType
2✔
6
from boa3.internal.model.type.primitive.nonetype import noneType
2✔
7

8

9
class OptionalType(UnionType):
2✔
10
    """
11
    An class used to represent Python Optional annotation type
12
    """
13

14
    def __init__(self, optional_types: set[IType] = None):
2✔
15
        if optional_types is None:
2✔
16
            union_types = None
2✔
17
        else:
18
            union_types = optional_types.copy()
2✔
19
            if noneType in optional_types:
2✔
20
                optional_types.remove(noneType)
2✔
21
            else:
UNCOV
22
                union_types.add(noneType)
×
23

24
        super().__init__(union_types)
2✔
25
        self._identifier = 'Optional'
2✔
26
        self._optional_type = optional_types if optional_types is not None else set()
2✔
27

28
    @property
2✔
29
    def identifier(self) -> str:
2✔
30
        return '{0}[{1}]'.format(self._identifier,
2✔
31
                                 ', '.join([t.identifier for t in self._optional_type]))
32

33
    @property
2✔
34
    def optional_types(self) -> list[IType]:
2✔
35
        return list(self._optional_type)
2✔
36

37
    def _is_type_of(self, value: Any) -> bool:
2✔
38
        if not isinstance(self._optional_type, Iterable) or len(self._optional_type) == 0:
2✔
39
            return False
2✔
40
        if isinstance(value, UnionType):
2✔
41
            return all(self._is_type_of(x) for x in value._union_types)
2✔
42
        return any(t.is_type_of(value) for t in self._union_types)
2✔
43

44
    @classmethod
2✔
45
    def build(cls, value: Any) -> IType:
2✔
46
        if isinstance(value, Iterable):
2✔
47
            value = set(value)
2✔
48
        else:
49
            value = {value}
2✔
50
        value.add(noneType)
2✔
51
        return super().build(value)
2✔
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