FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/SubclassShadowing.ql at codeql-cli/v2.15.4 · 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
461
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
/
SubclassShadowing.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (41 loc) · 1.52 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
SubclassShadowing.ql
Copy path
File metadata and controls
46 lines (41 loc) · 1.52 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
/**
* @name Superclass attribute shadows subclass method
* @description Defining an attribute in a superclass method with a name that matches a subclass
* method, hides the method in the subclass.
* @kind problem
* @problem.severity error
* @tags maintainability
* correctness
* @sub-severity low
* @precision high
* @id py/attribute-shadows-method
*/
/*
* Determine if a class defines a method that is shadowed by an attribute
* defined in a super-class
*/
/* Need to find attributes defined in superclass (only in __init__?) */
import
python
predicate
shadowed_by_super_class
(
ClassObject
c
,
ClassObject
supercls
,
Assign
assign
,
FunctionObject
f
)
{
c
.
getASuperType
(
)
=
supercls
and
c
.
declaredAttribute
(
_
)
=
f
and
exists
(
FunctionObject
init
,
Attribute
attr
|
supercls
.
declaredAttribute
(
"__init__"
)
=
init
and
attr
=
assign
.
getATarget
(
)
and
attr
.
getObject
(
)
.
(
Name
)
.
getId
(
)
=
"self"
and
attr
.
getName
(
)
=
f
.
getName
(
)
and
assign
.
getScope
(
)
=
init
.
getOrigin
(
)
.
(
FunctionExpr
)
.
getInnerScope
(
)
)
and
/*
* It's OK if the super class defines the method as well.
* We assume that the original method must have been defined for a reason.
*/
not
supercls
.
hasAttribute
(
f
.
getName
(
)
)
}
from
ClassObject
c
,
ClassObject
supercls
,
Assign
assign
,
FunctionObject
shadowed
where
shadowed_by_super_class
(
c
,
supercls
,
assign
,
shadowed
)
select
shadowed
.
getOrigin
(
)
,
"Method "
+
shadowed
.
getName
(
)
+
" is shadowed by an $@ in super class '"
+
supercls
.
getName
(
)
+
"'."
,
assign
,
"attribute"
Back
|
FazBrowse Home
|
New Git URL