FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/EqualsOrNotEquals.ql at codeql-cli/v2.19.2 · 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
997
Pull requests
467
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
/
Classes
/
EqualsOrNotEquals.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (41 loc) · 1.66 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
EqualsOrNotEquals.ql
Copy path
File metadata and controls
48 lines (41 loc) · 1.66 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
/**
* @name Inconsistent equality and inequality
* @description Defining only an equality method or an inequality method for a class violates the object model.
* @kind problem
* @tags reliability
* correctness
* @problem.severity warning
* @sub-severity high
* @precision very-high
* @id py/inconsistent-equality
*/
import
python
import
Equality
string
equals_or_ne
(
)
{
result
=
"__eq__"
or
result
=
"__ne__"
}
predicate
total_ordering
(
Class
cls
)
{
exists
(
Attribute
a
|
a
=
cls
.
getADecorator
(
)
|
a
.
getName
(
)
=
"total_ordering"
)
or
exists
(
Name
n
|
n
=
cls
.
getADecorator
(
)
|
n
.
getId
(
)
=
"total_ordering"
)
}
CallableValue
implemented_method
(
ClassValue
c
,
string
name
)
{
result
=
c
.
declaredAttribute
(
name
)
and
name
=
equals_or_ne
(
)
}
string
unimplemented_method
(
ClassValue
c
)
{
not
c
.
declaresAttribute
(
result
)
and
result
=
equals_or_ne
(
)
}
predicate
violates_equality_contract
(
ClassValue
c
,
string
present
,
string
missing
,
CallableValue
method
)
{
missing
=
unimplemented_method
(
c
)
and
method
=
implemented_method
(
c
,
present
)
and
not
c
.
failedInference
(
_
)
and
not
total_ordering
(
c
.
getScope
(
)
)
and
/* Python 3 automatically implements __ne__ if __eq__ is defined, but not vice-versa */
not
(
major_version
(
)
=
3
and
present
=
"__eq__"
and
missing
=
"__ne__"
)
and
not
method
.
getScope
(
)
instanceof
DelegatingEqualityMethod
and
not
c
.
lookup
(
missing
)
.
(
CallableValue
)
.
getScope
(
)
instanceof
DelegatingEqualityMethod
}
from
ClassValue
c
,
string
present
,
string
missing
,
CallableValue
method
where
violates_equality_contract
(
c
,
present
,
missing
,
method
)
select
method
,
"Class $@ implements "
+
present
+
" but does not implement "
+
missing
+
"."
,
c
,
c
.
getName
(
)
Back
|
FazBrowse Home
|
New Git URL