Skip to content

Commit cda14fe

Browse files
committed
Add more typing hinting
1 parent 6119697 commit cda14fe

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from src.api import debug # noqa
1313
from src.api import errors # noqa
1414
from src.api import errmsg # noqa
15+
from src.api import symboltable # noqa

src/api/global_.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
# the GNU General License
1010
# ----------------------------------------------------------------------
1111

12+
from typing import Dict
13+
from typing import Optional
14+
from typing import Set
15+
16+
import src.api
17+
18+
from .opcodestemps import OpcodesTemps
19+
from .constants import TYPE
20+
1221
# ----------------------------------------------------------------------
1322
# Simple global container for internal constants.
1423
# Internal constants might be architecture dependant. They're set
1524
# on module init (at __init__.py) on api.arch.<arch>/init.py
1625
#
1726
# Don't touch unless you know what are you doing
1827
# ----------------------------------------------------------------------
19-
from typing import Dict
20-
21-
from .opcodestemps import OpcodesTemps
22-
from .constants import TYPE
2328

2429
# ----------------------------------------------------------------------
2530
# Initializes a singleton container
@@ -73,7 +78,7 @@
7378
# ----------------------------------------------------------------------
7479
# Global Symbol Table
7580
# ----------------------------------------------------------------------
76-
SYMBOL_TABLE = None # Must be initialized with SymbolTable()
81+
SYMBOL_TABLE: Optional['src.api.symboltable.SymbolTable'] = None # Must be initialized with SymbolTable()
7782

7883
# ----------------------------------------------------------------------
7984
# Function calls pending to check
@@ -90,7 +95,7 @@
9095
# ----------------------------------------------------------------------
9196
# Initialization routines to be called automatically at program start
9297
# ----------------------------------------------------------------------
93-
INITS = set([])
98+
INITS: Set[str] = set([])
9499

95100
# ----------------------------------------------------------------------
96101
# FUNCTIONS pending to translate after parsing stage
@@ -156,7 +161,7 @@
156161
# ----------------------------------------------------------------------
157162
# Cache of Message errors to avoid repetition
158163
# ----------------------------------------------------------------------
159-
error_msg_cache = set()
164+
error_msg_cache: Set[str] = set()
160165

161166

162167
# ----------------------------------------------------------------------

src/symbols/number.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import numbers
1313

14+
from typing import Optional
15+
1416
from src.api.constants import CLASS
1517
from .symbol_ import Symbol
1618
from .type_ import SymbolTYPE
@@ -35,16 +37,15 @@ class SymbolNUMBER(Symbol):
3537
""" Defines an NUMBER symbol.
3638
"""
3739

38-
def __init__(self, value, lineno, type_=None):
40+
def __init__(self, value, lineno: int, type_: Optional[SymbolTYPE] = None):
3941
assert lineno is not None
4042
assert type_ is None or isinstance(type_, SymbolTYPE)
4143

4244
if isinstance(value, SymbolNUMBER):
4345
value = value.value
4446

4547
assert isinstance(value, numbers.Number)
46-
47-
super(SymbolNUMBER, self).__init__()
48+
super().__init__()
4849
self.class_ = CLASS.const
4950

5051
if int(value) == value:

0 commit comments

Comments
 (0)