diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-08-13 13:20:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-13 19:20:57 +0200 |
commit | 6f9c371c4f82281570869be2e4c609844bfd8c34 (patch) | |
tree | 355ae04c1a3b2121082ef8d61343ce4564905519 | |
parent | 93ee0a039de2d6aa99c4871b0b9d3db53fddf437 (diff) | |
download | pylint-git-6f9c371c4f82281570869be2e4c609844bfd8c34.tar.gz |
Revert "Fix the failure to lint modules contained under an identically named directory" (#7304)
This reverts commit 3ebb700aed88a427011c2e88705f66ec0b3830a4.
* Add regression test for namespace packages under directory on path
* Fix expected result in `test_relative_beyond_top_level_two`
-rw-r--r-- | doc/whatsnew/fragments/4444.bugfix | 3 | ||||
-rw-r--r-- | pylint/lint/expand_modules.py | 6 | ||||
-rw-r--r-- | tests/checkers/unittest_imports.py | 3 | ||||
-rw-r--r-- | tests/lint/unittest_lint.py | 17 |
4 files changed, 13 insertions, 16 deletions
diff --git a/doc/whatsnew/fragments/4444.bugfix b/doc/whatsnew/fragments/4444.bugfix deleted file mode 100644 index 5d9e3c07e..000000000 --- a/doc/whatsnew/fragments/4444.bugfix +++ /dev/null @@ -1,3 +0,0 @@ -Fix the failure to lint modules contained under an identically named directory. - -Closes #4444 diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index d5fe60661..27d4bd812 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -82,10 +82,8 @@ def expand_modules( continue module_path = get_python_path(something) additional_search_path = [".", module_path] + path - if os.path.isfile(something) or os.path.exists( - os.path.join(something, "__init__.py") - ): - # this is a file or a directory with an explicit __init__.py + if os.path.exists(something): + # this is a file or a directory try: modname = ".".join( modutils.modpath_from_file(something, path=additional_search_path) diff --git a/tests/checkers/unittest_imports.py b/tests/checkers/unittest_imports.py index c5b07e55f..a23354442 100644 --- a/tests/checkers/unittest_imports.py +++ b/tests/checkers/unittest_imports.py @@ -61,8 +61,7 @@ class TestImportsChecker(CheckerTestCase): ) output2, errors2 = capsys.readouterr() - # The first package fails to lint - assert len(output.split("\n")) == 1 + assert len(output.split("\n")) == 5 assert len(output2.split("\n")) == 5 assert errors == errors2 diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 27a6ba92c..2f3a5c170 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -944,10 +944,13 @@ def test_lint_namespace_package_under_dir(initialized_linter: PyLinter) -> None: assert not linter.stats.by_msg -def test_identically_named_nested_module(initialized_linter: PyLinter) -> None: - with tempdir(): - create_files(["identical/identical.py"]) - with open("identical/identical.py", "w", encoding="utf-8") as f: - f.write("import imp") - initialized_linter.check(["identical"]) - assert initialized_linter.stats.by_msg["deprecated-module"] == 1 +def test_lint_namespace_package_under_dir_on_path(initialized_linter: PyLinter) -> None: + """If the directory above a namespace package is on sys.path, + the namespace module under it is linted.""" + linter = initialized_linter + with tempdir() as tmpdir: + create_files(["namespace_on_path/submodule1.py"]) + os.chdir(tmpdir) + with fix_import_path([tmpdir]): + linter.check(["namespace_on_path"]) + assert linter.file_state.base_name == "namespace_on_path" |