summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorƁukasz Rogalski <rogalski.91@gmail.com>2017-01-28 10:45:26 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2017-01-28 11:45:26 +0200
commit48148a5092291323909052f7ce2fdfa97272057c (patch)
tree87d5c157f2b176a20aaa539c220d6d4903902f76
parent1a9721ec74f586bccdc9d88c7b85bfa0ec34155d (diff)
downloadastroid-git-48148a5092291323909052f7ce2fdfa97272057c.tar.gz
Mark __init_subclass__ as classmethod (#389)
-rw-r--r--astroid/scoped_nodes.py3
-rw-r--r--astroid/tests/unittest_scoped_nodes.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 31edb59e..71ab1c3a 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -14,6 +14,7 @@ new local scope in the language definition : Module, ClassDef, FunctionDef (and
Lambda, GeneratorExp, DictComp and SetComp to some extent).
"""
+import sys
import io
import itertools
import warnings
@@ -788,6 +789,8 @@ class FunctionDef(node_classes.Statement, Lambda):
if isinstance(frame, ClassDef):
if self.name == '__new__':
return 'classmethod'
+ elif sys.version_info >= (3, 6) and self.name == '__init_subclass__':
+ return 'classmethod'
else:
type_name = 'method'
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index e6ccb86d..d595cf71 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -594,6 +594,17 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase):
self.assertIsInstance(last_child, nodes.Return)
self.assertEqual(func.tolineno, 5)
+ @test_utils.require_version(minver='3.6')
+ def test_method_init_subclass(self):
+ klass = builder.extract_node('''
+ class MyClass:
+ def __init_subclass__(cls):
+ pass
+ ''')
+ method = klass['__init_subclass__']
+ self.assertEqual([n.name for n in method.args.args], ['cls'])
+ self.assertEqual(method.type, 'classmethod')
+
class ClassNodeTest(ModuleLoader, unittest.TestCase):