mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Adds fix for __init_subclass__ bug. (#2390)
* Adds fix for __init_subclass__ bug. * Adds test case. * Move test on name. I think it makes more sense here, alongside the other "special" method names.
This commit is contained in:
@@ -31,6 +31,7 @@ where
|
||||
cls.isNewStyle() and
|
||||
not name = "__new__" and
|
||||
not name = "__metaclass__" and
|
||||
not name = "__init_subclass__" and
|
||||
/* declared in scope */
|
||||
f.getScope() = cls.getScope()
|
||||
) and
|
||||
|
||||
@@ -117,3 +117,18 @@ class Z(zope.interface.Interface):
|
||||
pass
|
||||
|
||||
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
|
||||
# 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
|
||||
|
||||
class InitSubclass(object):
|
||||
def __init_subclass__(cls):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user