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

CityOfZion / neo3-boa / 5c8eab45-f99f-4697-a4ff-d2c04d4d17ac

01 Feb 2024 09:59PM UTC coverage: 92.107% (+0.5%) from 91.625%
5c8eab45-f99f-4697-a4ff-d2c04d4d17ac

push

circleci

Mirella de Medeiros
Bump version: 1.1.0 → 1.1.1

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

302 existing lines in 22 files now uncovered.

20784 of 22565 relevant lines covered (92.11%)

2.76 hits per line

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

92.78
/boa3/internal/model/type/classes/userclass.py
1
from typing import Any, Dict, List, Optional
3✔
2

3
from boa3.internal import constants
3✔
4
from boa3.internal.model.callable import Callable
3✔
5
from boa3.internal.model.method import Method
3✔
6
from boa3.internal.model.property import Property
3✔
7
from boa3.internal.model.symbol import ISymbol
3✔
8
from boa3.internal.model.type.classes.classarraytype import ClassArrayType
3✔
9
from boa3.internal.model.type.classes.classscope import ClassScope
3✔
10
from boa3.internal.model.type.classes.classtype import ClassType
3✔
11
from boa3.internal.model.type.itype import IType
3✔
12
from boa3.internal.model.variable import Variable
3✔
13

14

15
class UserClass(ClassArrayType):
3✔
16
    def __init__(self, identifier: str, decorators: List[Callable] = None,
3✔
17
                 bases: List[ClassType] = None):
18
        super(ClassArrayType, self).__init__(identifier, decorators, bases)
3✔
19

20
        self._static_methods: Dict[str, Method] = {}
3✔
21

22
        self._class_variables: Dict[str, Variable] = {}
3✔
23
        self._class_methods: Dict[str, Method] = {}
3✔
24

25
        self._instance_variables: Dict[str, Variable] = {}
3✔
26
        self._instance_methods: Dict[str, Method] = {}
3✔
27
        self._properties: Dict[str, Property] = {}
3✔
28

29
        self.imported_symbols = {}
3✔
30

31
    @property
3✔
32
    def shadowing_name(self) -> str:
3✔
33
        return 'class'
×
34

35
    @property
3✔
36
    def class_variables(self) -> Dict[str, Variable]:
3✔
37
        class_vars = super().class_variables
3✔
38
        class_vars.update(self._class_variables)
3✔
39
        return class_vars
3✔
40

41
    @property
3✔
42
    def instance_variables(self) -> Dict[str, Variable]:
3✔
43
        instance_vars = super().instance_variables
3✔
44
        instance_vars.update(self._instance_variables)
3✔
45
        return instance_vars
3✔
46

47
    @property
3✔
48
    def properties(self) -> Dict[str, Property]:
3✔
49
        props = super().properties
3✔
50
        props.update(self._properties)
3✔
51
        return props
3✔
52

53
    @property
3✔
54
    def static_methods(self) -> Dict[str, Method]:
3✔
55
        static_funcs = super().static_methods
3✔
56
        static_funcs.update(self._static_methods)
3✔
57
        return static_funcs
3✔
58

59
    @property
3✔
60
    def class_methods(self) -> Dict[str, Method]:
3✔
61
        class_funcs = super().class_methods
3✔
62
        class_funcs.update(self._class_methods)
3✔
63
        return class_funcs
3✔
64

65
    @property
3✔
66
    def instance_methods(self) -> Dict[str, Method]:
3✔
67
        instance_funcs = super().instance_methods
3✔
68
        instance_funcs.update(self._instance_methods)
3✔
69
        return instance_funcs
3✔
70

71
    def include_variable(self, var_id: str, var: Variable, is_instance: bool):
3✔
72
        """
73
        Includes a variable into the list of class variables
74

75
        :param var_id: variable identifier
76
        :param var: variable to be included
77
        :param is_instance: whether is a instance variable or a class variable
78
        """
79
        if not is_instance:
3✔
80
            self._class_variables[var_id] = var
3✔
81
        else:
82
            self._instance_variables[var_id] = var
3✔
83

84
    def include_property(self, prop_id: str, prop: Property):
3✔
85
        """
86
        Includes a property into the list of properties
87

88
        :param prop_id: property identifier
89
        :param prop: property to be included
90
        """
91
        self._properties[prop_id] = prop
3✔
92

93
    def include_callable(self, method_id: str, method: Callable, scope: ClassScope = ClassScope.INSTANCE) -> bool:
3✔
94
        """
95
        Includes a method into the scope of the class
96

97
        :param method_id: method identifier
98
        :param method: method to be included
99
        :param scope: which class scope this method should be included
100
        """
101
        from boa3.internal.model.builtin.builtin import Builtin
3✔
102
        if isinstance(method, Method):
3✔
103
            if Builtin.ClassMethodDecorator in method.decorators or scope is ClassScope.CLASS:
3✔
104
                methods_map = self._class_methods
3✔
105
            elif Builtin.StaticMethodDecorator in method.decorators or scope is ClassScope.STATIC:
3✔
106
                methods_map = self._static_methods
3✔
107
            else:
108
                methods_map = self._instance_methods
3✔
109

110
            if method_id not in methods_map:
3✔
111
                methods_map[method_id] = method
3✔
112
                return True
3✔
113

114
        return False
×
115

116
    def include_symbol(self, symbol_id: str, symbol: ISymbol, scope: ClassScope = ClassScope.INSTANCE):
3✔
117
        """
118
        Includes a method into the scope of the module
119

120
        :param symbol_id: method identifier
121
        :param symbol: method to be included
122
        :param scope: which class scope this symbol should be included
123
        """
124
        if symbol_id not in self.symbols:
3✔
125
            if isinstance(symbol, Variable):
3✔
126
                self.include_variable(symbol_id, symbol, scope == ClassScope.INSTANCE)
3✔
127
            elif isinstance(symbol, Property):
3✔
128
                self.include_property(symbol_id, symbol)
3✔
129
            elif isinstance(symbol, Callable):
×
130
                self.include_callable(symbol_id, symbol, scope)
×
131
            else:
132
                self.imported_symbols[symbol_id] = symbol
×
133

134
    def constructor_method(self) -> Optional[Method]:
3✔
135
        if constants.INIT_METHOD_ID not in self._class_methods:
3✔
136
            from boa3.internal.model.type.classes.classinitmethoddefault import ClassInitMethod
3✔
137
            self._class_methods[constants.INIT_METHOD_ID] = ClassInitMethod(self)
3✔
138

139
        return self._class_methods[constants.INIT_METHOD_ID]
3✔
140

141
    def is_type_of(self, value: Any) -> bool:
3✔
142
        if value is self:
3✔
143
            return True
3✔
144
        return any(base.is_type_of(value) for base in self.bases)
3✔
145

146
    @classmethod
3✔
147
    def _is_type_of(cls, value: Any) -> bool:
3✔
UNCOV
148
        return isinstance(value, UserClass)
×
149

150
    @classmethod
3✔
151
    def build(cls, value: Any) -> IType:
3✔
UNCOV
152
        return cls()
×
153

154

155
_EMPTY_CLASS = UserClass('-internal_use')
3✔
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