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:
Jakob Stoklund Olesen
2017-03-30 19:52:06 -07:00
parent fc979c474f
commit 98ecebd85b
4 changed files with 15 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ parser = argparse.ArgumentParser(description='Generate sources for Cretonne.')
parser.add_argument('--out-dir', help='set output directory')
args = parser.parse_args()
out_dir = args.out_dir # type: ignore
out_dir = args.out_dir
isas = isa.all_isas()

View File

@@ -60,7 +60,7 @@ def decode_interval(intv, full_range, default=None):
"""
if isinstance(intv, tuple):
# 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(hi)
assert lo <= hi

View File

@@ -289,9 +289,10 @@ class Level2Table(object):
Append the hash table to `level2_hashtables` and record the offset.
"""
hash_table = compute_quadratic(
self.lists.values(),
lambda enclist: enclist.inst.number)
def hash_func(enclist):
# type: (EncList) -> int
return enclist.inst.number
hash_table = compute_quadratic(self.lists.values(), hash_func)
self.hash_table_offset = len(level2_hashtables)
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`.
"""
hash_table = compute_quadratic(
level1.tables.values(),
lambda level2: level2.ty.number)
def hash_func(level2):
# type: (Level2Table) -> int
return level2.ty.number
hash_table = compute_quadratic(level1.tables.values(), hash_func)
with fmt.indented(
'pub static LEVEL1_{}: [Level1Entry<{}>; {}] = ['

View File

@@ -0,0 +1,5 @@
[mypy]
python_version = 2.7
disallow_untyped_defs = True
warn_unused_ignores = True
warn_return_any = True