Add mypy annotations.

pull/8013/head
Jussi Pakkanen 4 years ago
parent 26ffd4f8f2
commit f22d54690b
  1. 2
      mesonbuild/backend/ninjabackend.py
  2. 24
      mesonbuild/scripts/depscan.py

@ -135,7 +135,7 @@ Please report this error with a test case to the Meson bug tracker.'''.format(te
return quote_re.sub(r'$\g<0>', text) return quote_re.sub(r'$\g<0>', text)
class TargetDependencyScannerInfo: class TargetDependencyScannerInfo:
def __init__(self, private_dir, source2object): def __init__(self, private_dir: str, source2object: T.Dict[str, str]):
self.private_dir = private_dir self.private_dir = private_dir
self.source2object = source2object self.source2object = source2object

@ -23,17 +23,17 @@ import_re = re.compile('\w*import ([a-zA-Z0-9]+);')
export_re = re.compile('\w*export module ([a-zA-Z0-9]+);') export_re = re.compile('\w*export module ([a-zA-Z0-9]+);')
class DependencyScanner: class DependencyScanner:
def __init__(self, pickle_file, outfile, sources): def __init__(self, pickle_file: str, outfile: str, sources: T.List[str]):
with open(pickle_file, 'rb') as pf: with open(pickle_file, 'rb') as pf:
self.target_data = pickle.load(pf) self.target_data = pickle.load(pf) # type: TargetDependencyScannerInfo
self.outfile = outfile self.outfile = outfile
self.sources = sources self.sources = sources
self.provided_by = {} self.provided_by = {} # type: T.Dict[str, str]
self.exports = {} self.exports = {} # type: T.Dict[str, str]
self.needs = {} self.needs = {} # type: T.Dict[str, T.List[str]]
self.sources_with_exports = [] self.sources_with_exports = [] # type: T.List[str]
def scan_file(self, fname): def scan_file(self, fname: str) -> None:
for line in pathlib.Path(fname).read_text().split('\n'): for line in pathlib.Path(fname).read_text().split('\n'):
import_match = import_re.match(line) import_match = import_re.match(line)
export_match = export_re.match(line) export_match = export_re.match(line)
@ -51,13 +51,15 @@ class DependencyScanner:
self.provided_by[exported_module] = fname self.provided_by[exported_module] = fname
self.exports[fname] = exported_module self.exports[fname] = exported_module
def objname_for(self, src): def objname_for(self, src: str) -> str:
return self.target_data.source2object[src] objname = self.target_data.source2object[src]
assert(isinstance(objname, str))
return objname
def ifcname_for(self, src): def ifcname_for(self, src: str) -> str:
return '{}.ifc'.format(self.exports[src]) return '{}.ifc'.format(self.exports[src])
def scan(self): def scan(self) -> int:
for s in self.sources: for s in self.sources:
self.scan_file(s) self.scan_file(s)
with open(self.outfile, 'w') as ofile: with open(self.outfile, 'w') as ofile:

Loading…
Cancel
Save