FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Statements/TopLevelPrint.ql at codeql-cli/v2.15.5 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
998
Pull requests
460
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Statements
/
TopLevelPrint.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (36 loc) · 1.16 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Statements
/
TopLevelPrint.ql
Copy path
File metadata and controls
40 lines (36 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @name Use of a print statement at module level
* @description Using a print statement at module scope (except when guarded by `if __name__ == '__main__'`) will cause surprising output when the module is imported.
* @kind problem
* @tags reliability
* maintainability
* convention
* @problem.severity recommendation
* @sub-severity high
* @precision high
* @id py/print-during-import
*/
import
python
predicate
main_eq_name
(
If
i
)
{
exists
(
Name
n
,
StrConst
m
,
Compare
c
|
i
.
getTest
(
)
=
c
and
c
.
getLeft
(
)
=
n
and
c
.
getAComparator
(
)
=
m
and
n
.
getId
(
)
=
"__name__"
and
m
.
getText
(
)
=
"__main__"
)
}
predicate
is_print_stmt
(
Stmt
s
)
{
s
instanceof
Print
or
exists
(
ExprStmt
e
,
Call
c
,
Name
n
|
e
=
s
and
c
=
e
.
getValue
(
)
and
n
=
c
.
getFunc
(
)
and
n
.
getId
(
)
=
"print"
)
}
from
Stmt
p
where
is_print_stmt
(
p
)
and
// TODO: Need to discuss how we would like to handle ModuleObject.getKind in the glorious future
exists
(
ModuleValue
m
|
m
.
getScope
(
)
=
p
.
getScope
(
)
and
m
.
isUsedAsModule
(
)
)
and
not
exists
(
If
i
|
main_eq_name
(
i
)
and
i
.
getASubStatement
(
)
.
getASubStatement
*
(
)
=
p
)
select
p
,
"Print statement may execute during import."
Back
|
FazBrowse Home
|
New Git URL