Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative imports of modules in namespace packages (without __init__.py) #3609

Open
twmr opened this issue May 10, 2020 · 0 comments
Open

relative imports of modules in namespace packages (without __init__.py) #3609

twmr opened this issue May 10, 2020 · 0 comments

Comments

@twmr
Copy link
Contributor

twmr commented May 10, 2020

Steps to reproduce

  1. applying the following patch and running the two tests leads to one failure and one pass
 
-    def test_can_list_directories_without_dunder_init(self, tmpdir):
+    @pytest.mark.parametrize("modname", ['warning', 'warnings'])
+    def test_can_list_directories_without_dunder_init(self, tmpdir, modname):
         test_directory = tmpdir / "test_directory"
         test_directory.mkdir()
-        spam_module = test_directory / "spam.py"
-        spam_module.write("'Empty'")
+        l_module = test_directory / "logging.py"
+        l_module.write(f"'Empty'\nfrom .{modname} import A\nprint(A)")
+        w_module = test_directory / f"{modname}.py"
+        w_module.write("'Empty'\nA=3")

Current behavior

tests/self/test_run.py::TestRunTC::test_can_list_directories_without_dunder_init[warning] PASSED                                                                                                       [ 50%]
tests/self/test_run.py::TestRunTC::test_can_list_directories_without_dunder_init[warnings] FAILED  
...
E       AssertionError: expected output status 0, got 2. Below pylint output: 
E       ************* Module logging
E       test_directory/logging.py:2:0: E0402: Attempted relative import beyond top-level package (relative-beyond-top-level)
E       
E       ---------------------------------------------------------------------
E       Your code has been rated at -6.67/10 (previous run: -10.00/10, +3.33)


Expected behavior

Both tests pass, i.e., there should be no special handling of modules that are named after stdlib modules.

pylint --version output

pylint 2.6.0-dev1
astroid 2.5.0
Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 08:20:52) 
[GCC 7.3.0]
@twmr twmr changed the title relative imports of modules in packages without __init__ relative imports of modules in packages without __init__.py May 10, 2020
@twmr twmr changed the title relative imports of modules in packages without __init__.py relative imports of modules in namespace packages (without __init__.py) May 10, 2020
@PCManticore PCManticore added this to the 2.5.4 release milestone May 28, 2020
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.7.0, 2.7.x Feb 20, 2021
bonzini pushed a commit to qemu/qemu that referenced this issue May 30, 2021
Pylint 2.5.x - 2.7.x have regressions that make import checking
inconsistent, see:

pylint-dev/pylint#3609
pylint-dev/pylint#3624
pylint-dev/pylint#3651

Pinning to 2.4.4 is worse, because it mandates versions of shared
dependencies that are too old for features we want in isort and mypy.
Oh well.

Signed-off-by: John Snow <[email protected]>
Reviewed-by: Cleber Rosa <[email protected]>
Message-id: [email protected]
Signed-off-by: John Snow <[email protected]>
bonzini pushed a commit to qemu/qemu that referenced this issue Jun 2, 2021
Pylint 2.5.x - 2.7.x have regressions that make import checking
inconsistent, see:

pylint-dev/pylint#3609
pylint-dev/pylint#3624
pylint-dev/pylint#3651

Pinning to 2.4.4 is worse, because it mandates versions of shared
dependencies that are too old for features we want in isort and mypy.
Oh well.

Signed-off-by: John Snow <[email protected]>
Reviewed-by: Cleber Rosa <[email protected]>
Message-id: [email protected]
Signed-off-by: John Snow <[email protected]>
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.x, 2.15.0 May 9, 2022
@DanielNoord DanielNoord removed this from the 2.15.0 milestone Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants