Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/ql/src/Functions/NonSelf.ql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ where
not name = "__new__" and
not name = "__metaclass__" and
not name = "__init_subclass__" and
not name = "__class_getitem__" and
/* declared in scope */
f.getScope() = cls.getScope()
) and
Expand Down
15 changes: 11 additions & 4 deletions python/ql/test/query-tests/Functions/general/parameter_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,22 @@ def meth(arg):



# The `__init_subclass__` method is a new method introduced into Python 3.6
# which does not follow the normal conventions, and is in fact a class method
# 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 via LGTM as a false positive. For example,
# https://docs.python.org/3/reference/datamodel.html#customizing-class-creation
# `__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 InitSubclass(object):
class SpecialMethodNames(object):
def __init_subclass__(cls):
pass

def __class_getitem__(cls):
pass