mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Move tests to separate folder
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
| parameter_names.py:17:5:17:24 | Function n_cmethod | Class methods or methods of a type deriving from type should have 'cls', rather than 'self', as their first parameter. |
|
||||
| parameter_names.py:22:5:22:21 | Function n_cmethod2 | Class methods or methods of a type deriving from type should have 'cls' as their first parameter. |
|
||||
| parameter_names.py:37:5:37:20 | Function c_method | Class methods or methods of a type deriving from type should have 'cls', rather than 'y', as their first parameter. |
|
||||
@@ -0,0 +1 @@
|
||||
Functions/NonCls.ql
|
||||
@@ -0,0 +1,4 @@
|
||||
| om_test.py:71:5:71:19 | Function __repr__ | Normal methods should have at least one parameter (the first of which should be 'self'). |
|
||||
| parameter_names.py:50:5:50:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
|
||||
| parameter_names.py:53:5:53:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
|
||||
| parameter_names.py:56:5:56:20 | Function s_method2 | Normal methods should have at least one parameter (the first of which should be 'self'). |
|
||||
@@ -0,0 +1 @@
|
||||
Functions/NonSelf.ql
|
||||
@@ -0,0 +1,141 @@
|
||||
# Using name other than 'self' for first parameter in methods.
|
||||
# This shouldn't apply to classmethods (first parameter should be 'cls' or similar)
|
||||
# or static methods (first parameter can be anything)
|
||||
|
||||
|
||||
class Normal(object):
|
||||
|
||||
def n_ok(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def n_smethod(ok):
|
||||
pass
|
||||
|
||||
# not ok
|
||||
@classmethod
|
||||
def n_cmethod(self):
|
||||
pass
|
||||
|
||||
# not ok
|
||||
@classmethod
|
||||
def n_cmethod2():
|
||||
pass
|
||||
|
||||
# this is allowed because it has a decorator other than @classmethod
|
||||
@classmethod
|
||||
@id
|
||||
def n_suppress(any_name):
|
||||
pass
|
||||
|
||||
|
||||
class Class(type):
|
||||
|
||||
def __init__(cls):
|
||||
pass
|
||||
|
||||
def c_method(y):
|
||||
pass
|
||||
|
||||
def c_ok(cls):
|
||||
pass
|
||||
|
||||
@id
|
||||
def c_suppress(any_name):
|
||||
pass
|
||||
|
||||
|
||||
class NonSelf(object):
|
||||
|
||||
def __init__(x):
|
||||
pass
|
||||
|
||||
def s_method(y):
|
||||
pass
|
||||
|
||||
def s_method2():
|
||||
pass
|
||||
|
||||
def s_ok(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def s_smethod(ok):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def s_cmethod(cls):
|
||||
pass
|
||||
|
||||
def s_smethod2(ok):
|
||||
pass
|
||||
s_smethod2 = staticmethod(s_smethod2)
|
||||
|
||||
def s_cmethod2(cls):
|
||||
pass
|
||||
s_cmethod2 = classmethod(s_cmethod2)
|
||||
|
||||
#Possible FPs for non-self. ODASA-2439
|
||||
|
||||
class Acceptable1(object):
|
||||
def _func(f):
|
||||
return f
|
||||
_func(x)
|
||||
|
||||
class Acceptable2(object):
|
||||
def _func(f):
|
||||
return f
|
||||
|
||||
@_func
|
||||
def meth(self):
|
||||
pass
|
||||
|
||||
# Handling methods defined in a different scope than the class it belongs to,
|
||||
# gets problmematic since we need to show the full-path from method definition
|
||||
# to actually adding it to the class. We tried to enable warnings for these in
|
||||
# September 2019, but ended up sticking to the decision from ODASA-2439 (where
|
||||
# results are both obvious and useful to the end-user).
|
||||
def dont_care(arg):
|
||||
pass
|
||||
|
||||
class Acceptable3(object):
|
||||
|
||||
meth = dont_care
|
||||
|
||||
# OK
|
||||
class Meta(type):
|
||||
|
||||
#__new__ is an implicit class method, so the first arg is the metaclass
|
||||
def __new__(metacls, name, bases, cls_dict):
|
||||
return super(Meta, metacls).__new__(metacls, name, bases, cls_dict)
|
||||
|
||||
#ODASA-6062
|
||||
import zope.interface
|
||||
class Z(zope.interface.Interface):
|
||||
|
||||
def meth(arg):
|
||||
pass
|
||||
|
||||
Z().meth(0)
|
||||
|
||||
|
||||
|
||||
# The `__init_subclass__` (introduced in Python 3.6)
|
||||
# and `__class_getitem__` (introduced in Python 3.7) methods are methods
|
||||
# which do not follow the normal conventions, and are in fact class methods
|
||||
# despite not being marked as such with other means. The name alone is what
|
||||
# makes it such. As a consequence, the query `py/not-named-self` and other
|
||||
# relevant queries need to account for this.
|
||||
#
|
||||
# This has come up in the wild as a false positive. For example,
|
||||
# `__init_subclass__`:
|
||||
# https://docs.python.org/3/reference/datamodel.html#customizing-class-creation
|
||||
# `__class_getitem__`:
|
||||
# https://docs.python.org/3/reference/datamodel.html#emulating-generic-types
|
||||
|
||||
class SpecialMethodNames(object):
|
||||
def __init_subclass__(cls):
|
||||
pass
|
||||
|
||||
def __class_getitem__(cls):
|
||||
pass
|
||||
Reference in New Issue
Block a user