diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-07-03 00:31:09 -0400 |
---|---|---|
committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-08-03 08:43:01 -0400 |
commit | dbc60af70fced751859377f6377b186c6403cdee (patch) | |
tree | 13b70214802803e039a2289322f6ecfd05ba4823 | |
parent | 260aa939bf9faaa4975cce6e1922e189078b69ce (diff) | |
download | pylint-git-dbc60af70fced751859377f6377b186c6403cdee.tar.gz |
Fix the failure to lint modules contained under an identically named directory
-rw-r--r-- | doc/whatsnew/fragments/4444.bugfix | 3 | ||||
-rw-r--r-- | pylint/lint/expand_modules.py | 6 | ||||
-rw-r--r-- | tests/lint/unittest_lint.py | 9 |
3 files changed, 16 insertions, 2 deletions
diff --git a/doc/whatsnew/fragments/4444.bugfix b/doc/whatsnew/fragments/4444.bugfix new file mode 100644 index 000000000..5d9e3c07e --- /dev/null +++ b/doc/whatsnew/fragments/4444.bugfix @@ -0,0 +1,3 @@ +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 289e1afce..d90305f0d 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -82,8 +82,10 @@ def expand_modules( continue module_path = get_python_path(something) additional_search_path = [".", module_path] + path - if os.path.exists(something): - # this is a file or a directory + 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 try: modname = ".".join( modutils.modpath_from_file(something, path=additional_search_path) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index c9407bbc6..27a6ba92c 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -942,3 +942,12 @@ def test_lint_namespace_package_under_dir(initialized_linter: PyLinter) -> None: create_files(["outer/namespace/__init__.py", "outer/namespace/module.py"]) linter.check(["outer.namespace"]) 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 |