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:
Rebecca Valentine
2019-11-24 03:18:17 -08:00
committed by Taus
parent 5c3c8eb35d
commit a8204385c3
2 changed files with 16 additions and 0 deletions

View File

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

View File

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