Skip to content

Commit 5cc2efe

Browse files
committed
Python: Fix FPs for py/import-own-module
Before I added `--max-import-depth=2`, there was a bit of trouble, where it would alert on `from pkg_ok import foo2` -- since all the `pkg_ok.foo<n>` modules were missing, I guess the analysis didn't make any assumptions on whether `foo2` is a module or a regular attribute.
1 parent f3f9e34 commit 5cc2efe

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

python/ql/src/Imports/ModuleImportsItself.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import python
1414

1515
predicate modules_imports_itself(Import i, ModuleValue m) {
1616
i.getEnclosingModule() = m.getScope() and
17-
m.importedAs(i.getAnImportedModuleName())
17+
m = max(string s, ModuleValue m_ |
18+
s = i.getAnImportedModuleName() and
19+
m_.importedAs(s)
20+
|
21+
m_ order by s.length()
22+
)
1823
}
1924

2025
from Import i, ModuleValue m
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
| imports_test.py:8:1:8:19 | Import | The module 'imports_test' imports itself. |
22
| pkg_notok/__init__.py:4:1:4:16 | Import | The module 'pkg_notok' imports itself. |
3-
| pkg_notok/__init__.py:10:1:10:20 | Import | The module 'pkg_notok' imports itself. |
43
| pkg_notok/__init__.py:12:1:12:25 | Import | The module 'pkg_notok' imports itself. |
54
| pkg_notok/__init__.py:13:1:13:37 | Import | The module 'pkg_notok' imports itself. |
6-
| pkg_ok/__init__.py:1:1:1:26 | Import | The module 'pkg_ok' imports itself. |
7-
| pkg_ok/__init__.py:3:1:3:23 | Import | The module 'pkg_ok' imports itself. |
8-
| pkg_ok/__init__.py:4:1:4:28 | Import | The module 'pkg_ok' imports itself. |
9-
| pkg_ok/__init__.py:6:1:6:18 | Import | The module 'pkg_ok' imports itself. |
10-
| pkg_ok/__init__.py:7:1:7:22 | Import | The module 'pkg_ok' imports itself. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --max-import-depth=2
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import pkg_ok.foo1 as foo1 # TODO: FP
1+
import pkg_ok.foo1 as foo1
22

3-
from pkg_ok import foo2 # TODO: FP
4-
from pkg_ok.foo3 import Foo3 # TODO: FP
3+
from pkg_ok import foo2
4+
from pkg_ok.foo3 import Foo3
55

6-
from . import foo4 # TODO: FP
7-
from .foo5 import Foo5 # TODO: FP
6+
from . import foo4
7+
from .foo5 import Foo5

0 commit comments

Comments
 (0)