FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Functions/NonCls.ql at codeql-cli/v2.16.0 · 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
463
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
/
Functions
/
NonCls.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (45 loc) · 1.51 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Functions
/
NonCls.ql
Copy path
File metadata and controls
50 lines (45 loc) · 1.51 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
/**
* @name First parameter of a class method is not named 'cls'
* @description Using an alternative name for the first parameter of a class method makes code more
* difficult to read; PEP8 states that the first parameter to class methods should be 'cls'.
* @kind problem
* @tags maintainability
* readability
* convention
* @problem.severity recommendation
* @sub-severity high
* @precision high
* @id py/not-named-cls
*/
import
python
predicate
first_arg_cls
(
Function
f
)
{
exists
(
string
argname
|
argname
=
f
.
getArgName
(
0
)
|
argname
=
"cls"
or
/* Not PEP8, but relatively common */
argname
=
"mcls"
)
}
predicate
is_type_method
(
Function
f
)
{
exists
(
ClassValue
c
|
c
.
getScope
(
)
=
f
.
getScope
(
)
and
c
.
getASuperType
(
)
=
ClassValue
::
type
(
)
)
}
predicate
classmethod_decorators_only
(
Function
f
)
{
forall
(
Expr
decorator
|
decorator
=
f
.
getADecorator
(
)
|
decorator
.
(
Name
)
.
getId
(
)
=
"classmethod"
)
}
from
Function
f
,
string
message
where
(
f
.
getADecorator
(
)
.
(
Name
)
.
getId
(
)
=
"classmethod"
or
is_type_method
(
f
)
)
and
not
first_arg_cls
(
f
)
and
classmethod_decorators_only
(
f
)
and
not
f
.
getName
(
)
=
"__new__"
and
(
if
exists
(
f
.
getArgName
(
0
)
)
then
message
=
"Class methods or methods of a type deriving from type should have 'cls', rather than '"
+
f
.
getArgName
(
0
)
+
"', as their first parameter."
else
message
=
"Class methods or methods of a type deriving from type should have 'cls' as their first parameter."
)
select
f
,
message
Back
|
FazBrowse Home
|
New Git URL