diff options
-rw-r--r-- | pylint/checkers/imports.py | 3 | ||||
-rw-r--r-- | pylint/test/regrtest_data/bad_package/__init__.py | 2 | ||||
-rw-r--r-- | pylint/test/regrtest_data/bad_package/wrong.py | 5 | ||||
-rw-r--r-- | pylint/test/test_regr.py | 8 |
4 files changed, 17 insertions, 1 deletions
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 1969eeb..b195297 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -316,7 +316,8 @@ given file (report RP0402 must not be disabled)'} def _add_imported_module(self, node, importedmodname): """notify an imported module, used to analyze dependencies""" try: - importedmodname = get_module_part(importedmodname) + importedmodname = get_module_part(importedmodname, + node.root().file) except ImportError: pass context_name = node.root().name diff --git a/pylint/test/regrtest_data/bad_package/__init__.py b/pylint/test/regrtest_data/bad_package/__init__.py new file mode 100644 index 0000000..60585fd --- /dev/null +++ b/pylint/test/regrtest_data/bad_package/__init__.py @@ -0,0 +1,2 @@ +import missing
+raise missing.Missing..
\ No newline at end of file diff --git a/pylint/test/regrtest_data/bad_package/wrong.py b/pylint/test/regrtest_data/bad_package/wrong.py new file mode 100644 index 0000000..2d2d78f --- /dev/null +++ b/pylint/test/regrtest_data/bad_package/wrong.py @@ -0,0 +1,5 @@ +"""
+Test that pylint doesn't crash when a relative import
+depends on the local __init__, which contains an expected syntax error.
+"""
+from . import missing
diff --git a/pylint/test/test_regr.py b/pylint/test/test_regr.py index 42ee72c..6d800ab 100644 --- a/pylint/test/test_regr.py +++ b/pylint/test/test_regr.py @@ -137,6 +137,14 @@ class NonRegrTC(unittest.TestCase): got = linter.reporter.finalize().strip() self.assertEqual(got, "") + def test_no_context_file(self): + message = ("E: 2: invalid syntax\n" + "E: 5: No name 'missing' in module ''\n" + "W: 5: Unused import missing") + linter.check(join(REGR_DATA, 'bad_package')) + got = linter.reporter.finalize().strip() + self.assertEqual(got, message) + if __name__ == '__main__': unittest.main() |