|
13 | 13 | from src.api.constants import CLASS |
14 | 14 | from src.api.config import OPTIONS |
15 | 15 | from src.api.decorator import classproperty |
| 16 | + |
16 | 17 | from .symbol_ import Symbol |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class SymbolTYPE(Symbol): |
20 | 21 | """ A Type definition. Defines a type, |
21 | 22 | both user defined or basic ones. |
22 | 23 | """ |
23 | | - |
24 | | - def __init__(self, name, lineno, *children): |
| 24 | + def __init__(self, name: str, lineno: int, *children): |
25 | 25 | # All children (if any) must be SymbolTYPE |
26 | 26 | assert all(isinstance(x, SymbolTYPE) for x in children) |
27 | | - super(SymbolTYPE, self).__init__(*children) |
| 27 | + super().__init__(*children) |
28 | 28 | self.name = name # typename |
29 | 29 | self.lineno = lineno # The line the type was defined. Line 0 = basic type |
30 | 30 | self.final = self # self.final always return the original aliased type (if this type is an alias) |
@@ -78,7 +78,7 @@ def is_alias(self): |
78 | 78 | return False |
79 | 79 |
|
80 | 80 | def __eq__(self, other): |
81 | | - assert isinstance(other, SymbolTYPE) |
| 81 | + assert isinstance(other, SymbolTYPE), f"Invalid operand '{other}':{type(other)}" |
82 | 82 |
|
83 | 83 | if self is not self.final: |
84 | 84 | return self.final == other |
@@ -117,14 +117,14 @@ class SymbolBASICTYPE(SymbolTYPE): |
117 | 117 | If name is None or '', default typename from TYPES.to_string will be used. |
118 | 118 | """ |
119 | 119 |
|
120 | | - def __init__(self, type_, name=None): |
| 120 | + def __init__(self, type_, name: str = None): |
121 | 121 | """ type_ = Internal representation (e.g. TYPE.ubyte) |
122 | 122 | """ |
123 | 123 | assert TYPE.is_valid(type_) |
124 | 124 | if not name: |
125 | 125 | name = TYPE.to_string(type_) |
126 | 126 |
|
127 | | - super(SymbolBASICTYPE, self).__init__(name, 0) |
| 127 | + super().__init__(name, 0) |
128 | 128 | self.type_ = type_ |
129 | 129 |
|
130 | 130 | @property |
@@ -175,10 +175,9 @@ def __bool__(self): |
175 | 175 | class SymbolTYPEALIAS(SymbolTYPE): |
176 | 176 | """ Defines a type which is alias of another |
177 | 177 | """ |
178 | | - |
179 | | - def __init__(self, name, lineno, alias): |
| 178 | + def __init__(self, name, lineno: int, alias: SymbolTYPE): |
180 | 179 | assert isinstance(alias, SymbolTYPE) |
181 | | - super(SymbolTYPEALIAS, self).__init__(name, lineno, alias) |
| 180 | + super().__init__(name, lineno, alias) |
182 | 181 | self.final = alias.final |
183 | 182 |
|
184 | 183 | @property |
@@ -215,9 +214,9 @@ class SymbolTYPEREF(SymbolTYPEALIAS): |
215 | 214 | and if it was implicitly inferred or explicitly declared. |
216 | 215 | """ |
217 | 216 |
|
218 | | - def __init__(self, type_, lineno, implicit=False): |
| 217 | + def __init__(self, type_: SymbolTYPE, lineno: int, implicit: bool = False): |
219 | 218 | assert isinstance(type_, SymbolTYPE) |
220 | | - super(SymbolTYPEREF, self).__init__(type_.name, lineno, type_) |
| 219 | + super().__init__(type_.name, lineno, type_) |
221 | 220 | self.implicit = implicit |
222 | 221 |
|
223 | 222 | def to_signed(self): |
@@ -255,12 +254,12 @@ class Type(object): |
255 | 254 | _by_name = {x.name: x for x in types} |
256 | 255 |
|
257 | 256 | @staticmethod |
258 | | - def size(t): |
| 257 | + def size(t: SymbolTYPE): |
259 | 258 | assert isinstance(t, SymbolTYPE) |
260 | 259 | return t.size |
261 | 260 |
|
262 | 261 | @staticmethod |
263 | | - def to_string(t): |
| 262 | + def to_string(t: SymbolTYPE): |
264 | 263 | assert isinstance(t, SymbolTYPE) |
265 | 264 | return t.name |
266 | 265 |
|
@@ -292,37 +291,37 @@ def numbers(cls): |
292 | 291 | return tuple(list(cls.integrals) + list(cls.decimals)) |
293 | 292 |
|
294 | 293 | @classmethod |
295 | | - def is_numeric(cls, t): |
| 294 | + def is_numeric(cls, t: SymbolTYPE): |
296 | 295 | assert isinstance(t, SymbolTYPE) |
297 | 296 | return t.final in cls.numbers |
298 | 297 |
|
299 | 298 | @classmethod |
300 | | - def is_signed(cls, t): |
| 299 | + def is_signed(cls, t: SymbolTYPE): |
301 | 300 | assert isinstance(t, SymbolTYPE) |
302 | 301 | return t.final in cls.signed |
303 | 302 |
|
304 | 303 | @classmethod |
305 | | - def is_unsigned(cls, t): |
| 304 | + def is_unsigned(cls, t: SymbolTYPE): |
306 | 305 | assert isinstance(t, SymbolTYPE) |
307 | 306 | return t.final in cls.unsigned |
308 | 307 |
|
309 | 308 | @classmethod |
310 | | - def is_integral(cls, t): |
| 309 | + def is_integral(cls, t: SymbolTYPE): |
311 | 310 | assert isinstance(t, SymbolTYPE) |
312 | 311 | return t.final in cls.integrals |
313 | 312 |
|
314 | 313 | @classmethod |
315 | | - def is_decimal(cls, t): |
| 314 | + def is_decimal(cls, t: SymbolTYPE): |
316 | 315 | assert isinstance(t, SymbolTYPE) |
317 | 316 | return t.final in cls.decimals |
318 | 317 |
|
319 | 318 | @classmethod |
320 | | - def is_string(cls, t): |
| 319 | + def is_string(cls, t: SymbolTYPE): |
321 | 320 | assert isinstance(t, SymbolTYPE) |
322 | 321 | return t.final == cls.string |
323 | 322 |
|
324 | 323 | @classmethod |
325 | | - def to_signed(cls, t): |
| 324 | + def to_signed(cls, t: SymbolTYPE): |
326 | 325 | """ Return signed type or equivalent |
327 | 326 | """ |
328 | 327 | assert isinstance(t, SymbolTYPE) |
|
0 commit comments