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.
( )
indygreg |
hg-reviewers |
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.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | contrib/import-checker.py (2 lines) | |||
M | tests/test-imports-checker.t (6 lines) |
Status | Author | Revision | |
---|---|---|---|
Abandoned | martinvonz | ||
Abandoned | martinvonz | ||
Abandoned | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
yield msg('import should be relative: %s', fullname) | yield msg('import should be relative: %s', fullname) | ||||
# __future__ is special since it needs to come first and use | # __future__ is special since it needs to come first and use | ||||
# symbol import. | # symbol import. | ||||
if fullname != '__future__': | if fullname != '__future__': | ||||
if not fullname or ( | if not fullname or ( | ||||
fullname in stdlib_modules | fullname in stdlib_modules | ||||
# allow standard 'from typing import ...' style | # allow standard 'from typing import ...' style | ||||
and fullname != 'typing' | and fullname.startswith('.') | ||||
and fullname not in localmods | and fullname not in localmods | ||||
and fullname + '.__init__' not in localmods | and fullname + '.__init__' not in localmods | ||||
): | ): | ||||
yield msg('relative import of stdlib module') | yield msg('relative import of stdlib module') | ||||
else: | else: | ||||
seenlocal = fullname | seenlocal = fullname | ||||
# Direct symbol import is only allowed from certain modules and | # Direct symbol import is only allowed from certain modules and |
> import ui | > import ui | ||||
> EOF | > EOF | ||||
$ cat > testpackage/relativestdlib.py << EOF | $ cat > testpackage/relativestdlib.py << EOF | ||||
> from __future__ import absolute_import | > from __future__ import absolute_import | ||||
> from .. import os | > from .. import os | ||||
> EOF | > EOF | ||||
$ cat > testpackage/stdlibfrom.py << EOF | |||||
> from __future__ import absolute_import | |||||
> from collections import abc | |||||
> EOF | |||||
$ cat > testpackage/symbolimport.py << EOF | $ cat > testpackage/symbolimport.py << EOF | ||||
> from __future__ import absolute_import | > from __future__ import absolute_import | ||||
> from .unsorted import foo | > from .unsorted import foo | ||||
> EOF | > EOF | ||||
$ cat > testpackage/latesymbolimport.py << EOF | $ cat > testpackage/latesymbolimport.py << EOF | ||||
> from __future__ import absolute_import | > from __future__ import absolute_import | ||||
> from . import unsorted | > from . import unsorted | ||||
testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage | testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage | ||||
testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node | testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node | ||||
testpackage/multiple.py:2: multiple imported names: os, sys | testpackage/multiple.py:2: multiple imported names: os, sys | ||||
testpackage/multiplegroups.py:3: multiple "from . import" statements | testpackage/multiplegroups.py:3: multiple "from . import" statements | ||||
testpackage/relativestdlib.py:2: relative import of stdlib module | testpackage/relativestdlib.py:2: relative import of stdlib module | ||||
testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted | testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted | ||||
testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo | testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo | ||||
testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage | 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/levelpriority.py:3: higher-level import should come first: testpackage | ||||
testpackage/subpackage/localimport.py:7: multiple "from .. import" statements | testpackage/subpackage/localimport.py:7: multiple "from .. import" statements | ||||
testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority | testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority | ||||
testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted | testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted | ||||
testpackage/unsorted.py:3: imports not lexically sorted: os < sys | testpackage/unsorted.py:3: imports not lexically sorted: os < sys | ||||
testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node | testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node | ||||
[1] | [1] |