Skip to content

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

@twmr

Description

@twmr
Contributor

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]

Activity

changed the title [-]relative imports of modules in packages without __init__[/-] [+]relative imports of modules in packages without __init__.py[/+] on May 10, 2020
changed the title [-]relative imports of modules in packages without __init__.py[/-] [+]relative imports of modules in namespace packages (without __init__.py)[/+] on May 10, 2020
added this to the 2.5.4 release milestone on May 28, 2020
modified the milestones: 2.7.0, 2.7.x on Feb 20, 2021
modified the milestones: 2.x, 2.15.0 on May 9, 2022
removed this from the 2.15.0 milestone on Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @twmr@PCManticore@Pierre-Sassoulas@DanielNoord@jacobtylerwalls

        Issue actions

          relative imports of modules in namespace packages (without __init__.py) · Issue #3609 · pylint-dev/pylint