mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Merge pull request #2802 from RasmusWL/python-fix-fp-py/import-own-module
Python: Fix FP for py/import own module
This commit is contained in:
@@ -12,11 +12,16 @@
|
||||
|
||||
import python
|
||||
|
||||
predicate modules_imports_itself(Import i, ModuleValue m) {
|
||||
predicate modules_imports_itself(ImportingStmt 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
|
||||
from ImportingStmt i, ModuleValue m
|
||||
where modules_imports_itself(i, m)
|
||||
select i, "The module '" + m.getName() + "' imports itself."
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| imports_test.py:4:1:4:19 | Import | Module 'test_module2' is imported with both 'import' and 'import from' |
|
||||
| pkg_notok/__init__.py:4:1:4:16 | Import | Module 'pkg_notok' is imported with both 'import' and 'import from' |
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
| 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: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_notok/__init__.py:14:1:14:23 | from pkg_notok import * | The module 'pkg_notok' imports itself. |
|
||||
|
||||
@@ -7,3 +7,5 @@ from test_module2 import func
|
||||
#Module imports itself
|
||||
import imports_test
|
||||
|
||||
import pkg_ok
|
||||
import pkg_notok
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --max-import-depth=2
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo(object):
|
||||
pass
|
||||
|
||||
import pkg_notok
|
||||
|
||||
# This import is a bit tricky. It will make `bar` available in as `pkg_notok.bar` as a
|
||||
# side effect (see https://docs.python.org/3/reference/import.html#submodules), but the
|
||||
# *import* will add a binding to `pkg_notok` to the current scope -- so technically the
|
||||
# module imports itself.
|
||||
import pkg_notok.bar
|
||||
|
||||
from pkg_notok import Foo
|
||||
from pkg_notok import Foo as NotOkFoo
|
||||
from pkg_notok import *
|
||||
@@ -0,0 +1,2 @@
|
||||
class Bar():
|
||||
pass
|
||||
@@ -0,0 +1,7 @@
|
||||
import pkg_ok.foo1 as foo1
|
||||
|
||||
from pkg_ok import foo2
|
||||
from pkg_ok.foo3 import Foo3
|
||||
|
||||
from . import foo4
|
||||
from .foo5 import Foo5
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo1():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo2():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo3():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo4():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo5():
|
||||
pass
|
||||
Reference in New Issue
Block a user