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.
This commit is contained in:
Rasmus Wriedt Larsen
2020-02-11 11:37:01 +01:00
parent f3f9e340d3
commit 5cc2efef8e
4 changed files with 12 additions and 12 deletions

View File

@@ -14,7 +14,12 @@ import python
predicate modules_imports_itself(Import i, ModuleValue m) {
i.getEnclosingModule() = m.getScope() and
m.importedAs(i.getAnImportedModuleName())
m = max(string s, ModuleValue m_ |
s = i.getAnImportedModuleName() and
m_.importedAs(s)
|
m_ order by s.length()
)
}
from Import i, ModuleValue m

View File

@@ -1,10 +1,4 @@
| imports_test.py:8:1:8:19 | Import | The module 'imports_test' imports itself. |
| pkg_notok/__init__.py:4:1:4:16 | Import | The module 'pkg_notok' imports itself. |
| pkg_notok/__init__.py:10:1:10:20 | Import | The module 'pkg_notok' imports itself. |
| pkg_notok/__init__.py:12:1:12:25 | Import | The module 'pkg_notok' imports itself. |
| pkg_notok/__init__.py:13:1:13:37 | Import | The module 'pkg_notok' imports itself. |
| pkg_ok/__init__.py:1:1:1:26 | Import | The module 'pkg_ok' imports itself. |
| pkg_ok/__init__.py:3:1:3:23 | Import | The module 'pkg_ok' imports itself. |
| pkg_ok/__init__.py:4:1:4:28 | Import | The module 'pkg_ok' imports itself. |
| pkg_ok/__init__.py:6:1:6:18 | Import | The module 'pkg_ok' imports itself. |
| pkg_ok/__init__.py:7:1:7:22 | Import | The module 'pkg_ok' imports itself. |

View File

@@ -0,0 +1 @@
semmle-extractor-options: --max-import-depth=2

View File

@@ -1,7 +1,7 @@
import pkg_ok.foo1 as foo1 # TODO: FP
import pkg_ok.foo1 as foo1
from pkg_ok import foo2 # TODO: FP
from pkg_ok.foo3 import Foo3 # TODO: FP
from pkg_ok import foo2
from pkg_ok.foo3 import Foo3
from . import foo4 # TODO: FP
from .foo5 import Foo5 # TODO: FP
from . import foo4
from .foo5 import Foo5