diff --git a/mesonbuild/depfile.py b/mesonbuild/depfile.py index 62cbe8125..a8b458823 100644 --- a/mesonbuild/depfile.py +++ b/mesonbuild/depfile.py @@ -11,12 +11,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import collections +import typing as T -def parse(lines): - rules = [] - targets = [] - deps = [] + +def parse(lines: T.Iterable[str]) -> T.List[T.Tuple[T.List[str], T.List[str]]]: + rules: T.List[T.Tuple[T.List[str], T.List[str]]] = [] + targets: T.List[str] = [] + deps: T.List[str] = [] in_deps = False out = '' for line in lines: @@ -56,12 +57,15 @@ def parse(lines): out += c return rules -Target = collections.namedtuple('Target', ['deps']) +class Target(T.NamedTuple): + + deps: T.Set[str] + class DepFile: - def __init__(self, lines): + def __init__(self, lines: T.Iterable[str]): rules = parse(lines) - depfile = {} + depfile: T.Dict[str, Target] = {} for (targets, deps) in rules: for target in targets: t = depfile.setdefault(target, Target(deps=set())) @@ -69,16 +73,17 @@ class DepFile: t.deps.add(dep) self.depfile = depfile - def get_all_dependencies(self, target, visited=None): - deps = set() + def get_all_dependencies(self, name: str, visited: T.Optional[T.Set[str]] = None) -> T.List[str]: + deps: T.Set[str] = set() if not visited: visited = set() - if target in visited: - return set() - visited.add(target) - target = self.depfile.get(target) + if name in visited: + return [] + visited.add(name) + + target = self.depfile.get(name) if not target: - return set() + return [] deps.update(target.deps) for dep in target.deps: deps.update(self.get_all_dependencies(dep, visited)) diff --git a/run_mypy.py b/run_mypy.py index 1c2d64498..1c2759a52 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -25,6 +25,7 @@ modules = [ 'mesonbuild/arglist.py', 'mesonbuild/backend/backends.py', # 'mesonbuild/coredata.py', + 'mesonbuild/depfile.py', 'mesonbuild/envconfig.py', 'mesonbuild/interpreter/compiler.py', 'mesonbuild/interpreter/mesonmain.py',