Skip to content

Python: Fix false positive in py/unintentional-import. #4062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/ql/src/Imports/UnintentionalImport.ql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ predicate all_defined(ModuleValue exporter) {
}

from ImportStar imp, ModuleValue exporter
where import_star(imp, exporter) and not all_defined(exporter)
where import_star(imp, exporter) and not all_defined(exporter) and not exporter.isAbsent()
select imp,
"Import pollutes the enclosing namespace, as the imported module $@ does not define '__all__'.",
exporter, exporter.getName()
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
| imports_test.py:21:1:21:20 | from module import * | Using 'from ... import *' pollutes the namespace |
| imports_test.py:22:1:22:32 | from module_without_all import * | Using 'from ... import *' pollutes the namespace |
| imports_test.py:65:1:65:40 | from module_that_does_not_exist import * | Using 'from ... import *' pollutes the namespace |
2 changes: 2 additions & 0 deletions python/ql/test/query-tests/Imports/general/imports_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ def __init__(self):
#Use it
different

# FP reported in https://github.com/github/codeql/issues/4003
from module_that_does_not_exist import *