FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Statements/UnreachableCode.ql at codeql-cli-2.11.3 · github/codeql · GitHub
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Issues
1k
Pull requests
468
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
/
UnreachableCode.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (57 loc) · 1.65 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Statements
/
UnreachableCode.ql
Copy path
File metadata and controls
64 lines (57 loc) · 1.65 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @name Unreachable code
* @description Code is unreachable
* @kind problem
* @tags maintainability
* useless-code
* external/cwe/cwe-561
* @problem.severity warning
* @sub-severity low
* @precision very-high
* @id py/unreachable-statement
*/
import
python
predicate
typing_import
(
ImportingStmt
is
)
{
exists
(
Module
m
|
is
.
getScope
(
)
=
m
and
exists
(
TypeHintComment
tc
|
tc
.
getLocation
(
)
.
getFile
(
)
=
m
.
getFile
(
)
)
)
}
/** Holds if `s` contains the only `yield` in scope */
predicate
unique_yield
(
Stmt
s
)
{
exists
(
Yield
y
|
s
.
contains
(
y
)
)
and
exists
(
Function
f
|
f
=
s
.
getScope
(
)
and
strictcount
(
Yield
y
|
f
.
containsInScope
(
y
)
)
=
1
)
}
/** Holds if `contextlib.suppress` may be used in the same scope as `s` */
predicate
suppression_in_scope
(
Stmt
s
)
{
exists
(
With
w
|
w
.
getContextExpr
(
)
.
(
Call
)
.
getFunc
(
)
.
pointsTo
(
Value
::
named
(
"contextlib.suppress"
)
)
and
w
.
getScope
(
)
=
s
.
getScope
(
)
)
}
/** Holds if `s` is a statement that raises an exception at the end of an if-elif-else chain. */
predicate
marks_an_impossible_else_branch
(
Stmt
s
)
{
exists
(
If
i
|
i
.
getOrelse
(
)
.
getItem
(
0
)
=
s
|
s
.
(
Assert
)
.
getTest
(
)
instanceof
False
or
s
instanceof
Raise
)
}
predicate
reportable_unreachable
(
Stmt
s
)
{
s
.
isUnreachable
(
)
and
not
typing_import
(
s
)
and
not
suppression_in_scope
(
s
)
and
not
exists
(
Stmt
other
|
other
.
isUnreachable
(
)
|
other
.
contains
(
s
)
or
exists
(
StmtList
l
,
int
i
,
int
j
|
l
.
getItem
(
i
)
=
other
and
l
.
getItem
(
j
)
=
s
and
i
<
j
)
)
and
not
unique_yield
(
s
)
and
not
marks_an_impossible_else_branch
(
s
)
}
from
Stmt
s
where
reportable_unreachable
(
s
)
select
s
,
"This statement is unreachable."
Back
|
FazBrowse Home
|
New Git URL