Skip to content

Commit 7f9ae87

Browse files
committed
Merge #20451: lint: run mypy over contrib/devtools
1ef2138 lint: run mypy over contrib/devtools (fanquake) Pull request description: wumpus mentioned on IRC that we don't currently run `mypy` over the `contrib/devtools` directory, and that it would likely be worthwhile given #20434. This just adds that dir to the linter, as well as some missing annotations to fix existing errors. Note that now we require Python 3.6 we can make use of variable annotations. master (patched to check contrib devtools): ```bash test/lint/lint-python.sh contrib/devtools/symbol-check.py:154: error: Incompatible types in assignment (expression has type "List[str]", variable has type "str") contrib/devtools/circular-dependencies.py:35: error: Need type annotation for 'deps' (hint: "deps: Dict[<type>, <type>] = ...") contrib/devtools/circular-dependencies.py:67: error: Need type annotation for 'closure' (hint: "closure: Dict[<type>, <type>] = ...") Found 4 errors in 3 files (checked 187 source files) ``` I haven't quite gone as far as to add annotations like ```python CHECKS: Dict[str, List[Tuple[str, Callable[[Any], bool]]]] = {... ``` to `symbol-check.py`. ACKs for top commit: laanwj: ACK 1ef2138 Tree-SHA512: a58c2ece588c640289dc1d35dad5b1b8732788272daa0965d6bf44ee8a7f7c8e8585f94d233ac41c84b9ffcfc97841a00fe2c9acba41f58fd164f01de4b6512b
2 parents ddbf7a6 + 1ef2138 commit 7f9ae87

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

contrib/devtools/circular-dependencies.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import sys
77
import re
8+
from typing import Dict, List, Set
89

910
MAPPING = {
1011
'core_read.cpp': 'core_io.cpp',
@@ -32,7 +33,7 @@ def module_name(path):
3233
return None
3334

3435
files = dict()
35-
deps = dict()
36+
deps: Dict[str, Set[str]] = dict()
3637

3738
RE = re.compile("^#include <(.*)>")
3839

@@ -59,12 +60,12 @@ def module_name(path):
5960
deps[module].add(included_module)
6061

6162
# Loop to find the shortest (remaining) circular dependency
62-
have_cycle = False
63+
have_cycle: bool = False
6364
while True:
6465
shortest_cycle = None
6566
for module in sorted(deps.keys()):
6667
# Build the transitive closure of dependencies of module
67-
closure = dict()
68+
closure: Dict[str, List[str]] = dict()
6869
for dep in deps[module]:
6970
closure[dep] = []
7071
while True:

contrib/devtools/symbol-check.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def check_version(max_versions, version, arch) -> bool:
157157
def check_imported_symbols(filename) -> bool:
158158
elf = pixie.load(filename)
159159
cppfilt = CPPFilt()
160-
ok = True
160+
ok: bool = True
161161

162162
for symbol in elf.dyn_symbols:
163163
if not symbol.is_import:
@@ -172,7 +172,7 @@ def check_imported_symbols(filename) -> bool:
172172
def check_exported_symbols(filename) -> bool:
173173
elf = pixie.load(filename)
174174
cppfilt = CPPFilt()
175-
ok = True
175+
ok: bool = True
176176
for symbol in elf.dyn_symbols:
177177
if not symbol.is_export:
178178
continue
@@ -184,7 +184,7 @@ def check_exported_symbols(filename) -> bool:
184184
return ok
185185

186186
def check_ELF_libraries(filename) -> bool:
187-
ok = True
187+
ok: bool = True
188188
elf = pixie.load(filename)
189189
for library_name in elf.query_dyn_tags(pixie.DT_NEEDED):
190190
assert(isinstance(library_name, bytes))
@@ -207,7 +207,7 @@ def macho_read_libraries(filename) -> List[str]:
207207
return libraries
208208

209209
def check_MACHO_libraries(filename) -> bool:
210-
ok = True
210+
ok: bool = True
211211
for dylib in macho_read_libraries(filename):
212212
if dylib not in MACHO_ALLOWED_LIBRARIES:
213213
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
@@ -227,7 +227,7 @@ def pe_read_libraries(filename) -> List[str]:
227227
return libraries
228228

229229
def check_PE_libraries(filename) -> bool:
230-
ok = True
230+
ok: bool = True
231231
for dylib in pe_read_libraries(filename):
232232
if dylib not in PE_ALLOWED_LIBRARIES:
233233
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
@@ -260,7 +260,7 @@ def identify_executable(executable) -> Optional[str]:
260260
return None
261261

262262
if __name__ == '__main__':
263-
retval = 0
263+
retval: int = 0
264264
for filename in sys.argv[1:]:
265265
try:
266266
etype = identify_executable(filename)
@@ -269,7 +269,7 @@ def identify_executable(executable) -> Optional[str]:
269269
retval = 1
270270
continue
271271

272-
failed = []
272+
failed: List[str] = []
273273
for (name, func) in CHECKS[etype]:
274274
if not func(filename):
275275
failed.append(name)

test/lint/lint-python.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ if ! PYTHONWARNINGS="ignore" flake8 --ignore=B,C,E,F,I,N,W --select=$(IFS=","; e
102102
EXIT_CODE=1
103103
fi
104104

105-
if ! mypy --ignore-missing-imports $(git ls-files "test/functional/*.py"); then
105+
if ! mypy --ignore-missing-imports $(git ls-files "test/functional/*.py" "contrib/devtools/*.py"); then
106106
EXIT_CODE=1
107107
fi
108108

0 commit comments

Comments
 (0)