Python: Handle __class_getitem__ in py/not-named-self (#2825)

Fixes #2824
This commit is contained in:
jack1142
2020-02-13 13:38:36 +01:00
committed by GitHub
parent dcb41a139c
commit e1644dd68b
2 changed files with 12 additions and 4 deletions

View File

@@ -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

View File

@@ -120,15 +120,22 @@ Z().meth(0)
# 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