summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pylint/test/input/not__init__.py1
-rw-r--r--pylint/test/unittest_lint.py14
-rw-r--r--pylint/utils.py2
3 files changed, 16 insertions, 1 deletions
diff --git a/pylint/test/input/not__init__.py b/pylint/test/input/not__init__.py
new file mode 100644
index 000000000..60e92b76c
--- /dev/null
+++ b/pylint/test/input/not__init__.py
@@ -0,0 +1 @@
+"""test"""
diff --git a/pylint/test/unittest_lint.py b/pylint/test/unittest_lint.py
index a6e401cbb..0c48b49be 100644
--- a/pylint/test/unittest_lint.py
+++ b/pylint/test/unittest_lint.py
@@ -745,3 +745,17 @@ def test_custom_should_analyze_file():
messages = reporter.messages
assert len(messages) == 1
assert 'invalid syntax' in messages[0]
+
+
+def test_filename_with__init__(init_linter):
+ # This tracks a regression where a file whose name ends in __init__.py,
+ # such as flycheck__init__.py, would accidentally lead to linting the
+ # entire containing directory.
+ reporter = testutils.TestReporter()
+ linter = init_linter
+ linter.open()
+ linter.set_reporter(reporter)
+ filepath = join(INPUTDIR, 'not__init__.py')
+ linter.check([filepath])
+ messages = reporter.messages
+ assert len(messages) == 0
diff --git a/pylint/utils.py b/pylint/utils.py
index 1ace59392..4dbfd9e1a 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -881,7 +881,7 @@ def expand_modules(files_or_modules, black_list, black_list_re):
'basepath': filepath, 'basename': modname})
has_init = (not (modname.endswith('.__init__') or modname == '__init__')
- and '__init__.py' in filepath)
+ and basename(filepath) == '__init__.py')
if has_init or is_namespace or is_directory:
for subfilepath in modutils.get_module_files(dirname(filepath), black_list,