diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -88,9 +88,8 @@ def fromlocalfunc(modulename, localmods) `modulename` is an `dotted_name_of_path()`-ed source file path, which may have `.__init__` at the end of it, of the target source. - `localmods` is a dict (or set), of which key is an absolute - `dotted_name_of_path()`-ed source file path of locally defined (= - Mercurial specific) modules. + `localmods` is a set of absolute `dotted_name_of_path()`-ed source file + paths of locally defined (= Mercurial specific) modules. This function assumes that module names not existing in `localmods` are from the Python standard library. @@ -114,9 +113,9 @@ def fromlocalfunc(modulename, localmods) convenient, even though this is also equivalent to "absname != dottednpath") - >>> localmods = {'foo.__init__': True, 'foo.foo1': True, - ... 'foo.bar.__init__': True, 'foo.bar.bar1': True, - ... 'baz.__init__': True, 'baz.baz1': True } + >>> localmods = {'foo.__init__', 'foo.foo1', + ... 'foo.bar.__init__', 'foo.bar.bar1', + ... 'baz.__init__', 'baz.baz1'} >>> fromlocal = fromlocalfunc('foo.xxx', localmods) >>> # relative >>> fromlocal('foo1') @@ -257,7 +256,7 @@ def imported_modules(source, modulename, Args: source: The python source to examine as a string. modulename: of specified python source (may have `__init__`) - localmods: dict of locally defined module names (may have `__init__`) + localmods: set of locally defined module names (may have `__init__`) ignore_nested: If true, import statements that do not start in column zero will be ignored. @@ -696,13 +695,14 @@ def main(argv): if argv[1] == '-': argv = argv[:1] argv.extend(l.rstrip() for l in sys.stdin.readlines()) - localmods = {} + localmodpaths = {} used_imports = {} any_errors = False for source_path in argv[1:]: modname = dotted_name_of_path(source_path) - localmods[modname] = source_path - for localmodname, source_path in sorted(localmods.items()): + localmodpaths[modname] = source_path + localmods = set(localmodpaths) + for localmodname, source_path in sorted(localmodpaths.items()): for src, modname, name, line in sources(source_path, localmodname): try: used_imports[modname] = sorted(