# HG changeset patch # User Martin von Zweigbergk # Date 2019-12-18 21:39:44 # Node ID 303576116ac19a13862e6b408f9d32c13ad7edf2 # Parent d825e7e0ca6eb5025c410dfd634625523fa071f8 import-checker: allow all absolute imports of stdlib modules Before this patch, we didn't allow imports like from importlib import resources (That's the reason I used `import importlib.resources` in D7629.) I think that form is still an absolute import, so I don't think we forbade on purpose. Differential Revision: https://phab.mercurial-scm.org/D7700 diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -536,7 +536,7 @@ def verify_modern_convention(module, roo if not fullname or ( fullname in stdlib_modules # allow standard 'from typing import ...' style - and fullname != 'typing' + and fullname.startswith('.') and fullname not in localmods and fullname + '.__init__' not in localmods ): diff --git a/tests/test-imports-checker.t b/tests/test-imports-checker.t --- a/tests/test-imports-checker.t +++ b/tests/test-imports-checker.t @@ -47,6 +47,11 @@ Run additional tests for the import chec > from .. import os > EOF + $ cat > testpackage/stdlibfrom.py << EOF + > from __future__ import absolute_import + > from collections import abc + > EOF + $ cat > testpackage/symbolimport.py << EOF > from __future__ import absolute_import > from .unsorted import foo @@ -150,6 +155,7 @@ Run additional tests for the import chec testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage + testpackage/stdlibfrom.py:2: direct symbol import abc from collections testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage testpackage/subpackage/localimport.py:7: multiple "from .. import" statements testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority