Add a mypy.ini file and enable some more warnings.
Also require all Python functions to have a type declaration.
This commit is contained in:
@@ -18,7 +18,7 @@ parser = argparse.ArgumentParser(description='Generate sources for Cretonne.')
|
|||||||
parser.add_argument('--out-dir', help='set output directory')
|
parser.add_argument('--out-dir', help='set output directory')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
out_dir = args.out_dir # type: ignore
|
out_dir = args.out_dir
|
||||||
|
|
||||||
isas = isa.all_isas()
|
isas = isa.all_isas()
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ def decode_interval(intv, full_range, default=None):
|
|||||||
"""
|
"""
|
||||||
if isinstance(intv, tuple):
|
if isinstance(intv, tuple):
|
||||||
# mypy buig here: 'builtins.None' object is not iterable
|
# mypy buig here: 'builtins.None' object is not iterable
|
||||||
lo, hi = intv # type: ignore
|
lo, hi = intv
|
||||||
assert is_power_of_two(lo)
|
assert is_power_of_two(lo)
|
||||||
assert is_power_of_two(hi)
|
assert is_power_of_two(hi)
|
||||||
assert lo <= hi
|
assert lo <= hi
|
||||||
|
|||||||
@@ -289,9 +289,10 @@ class Level2Table(object):
|
|||||||
|
|
||||||
Append the hash table to `level2_hashtables` and record the offset.
|
Append the hash table to `level2_hashtables` and record the offset.
|
||||||
"""
|
"""
|
||||||
hash_table = compute_quadratic(
|
def hash_func(enclist):
|
||||||
self.lists.values(),
|
# type: (EncList) -> int
|
||||||
lambda enclist: enclist.inst.number)
|
return enclist.inst.number
|
||||||
|
hash_table = compute_quadratic(self.lists.values(), hash_func)
|
||||||
|
|
||||||
self.hash_table_offset = len(level2_hashtables)
|
self.hash_table_offset = len(level2_hashtables)
|
||||||
self.hash_table_len = len(hash_table)
|
self.hash_table_len = len(hash_table)
|
||||||
@@ -402,9 +403,10 @@ def emit_level1_hashtable(cpumode, level1, offt, fmt):
|
|||||||
"""
|
"""
|
||||||
Emit a level 1 hash table for `cpumode`.
|
Emit a level 1 hash table for `cpumode`.
|
||||||
"""
|
"""
|
||||||
hash_table = compute_quadratic(
|
def hash_func(level2):
|
||||||
level1.tables.values(),
|
# type: (Level2Table) -> int
|
||||||
lambda level2: level2.ty.number)
|
return level2.ty.number
|
||||||
|
hash_table = compute_quadratic(level1.tables.values(), hash_func)
|
||||||
|
|
||||||
with fmt.indented(
|
with fmt.indented(
|
||||||
'pub static LEVEL1_{}: [Level1Entry<{}>; {}] = ['
|
'pub static LEVEL1_{}: [Level1Entry<{}>; {}] = ['
|
||||||
|
|||||||
5
lib/cretonne/meta/mypy.ini
Normal file
5
lib/cretonne/meta/mypy.ini
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[mypy]
|
||||||
|
python_version = 2.7
|
||||||
|
disallow_untyped_defs = True
|
||||||
|
warn_unused_ignores = True
|
||||||
|
warn_return_any = True
|
||||||
Reference in New Issue
Block a user