diff options
-rw-r--r-- | astroid/tests/unittest_scoped_nodes.py | 10 | ||||
-rw-r--r-- | astroid/tree/scoped_nodes.py | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py index 0eb2afad..e6ba9ec5 100644 --- a/astroid/tests/unittest_scoped_nodes.py +++ b/astroid/tests/unittest_scoped_nodes.py @@ -572,6 +572,16 @@ 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): diff --git a/astroid/tree/scoped_nodes.py b/astroid/tree/scoped_nodes.py index 7e44b27a..626c10e8 100644 --- a/astroid/tree/scoped_nodes.py +++ b/astroid/tree/scoped_nodes.py @@ -13,6 +13,7 @@ new local scope in the language definition : Module, ClassDef, FunctionDef (and Lambda, GeneratorExp, DictComp and SetComp to some extent). """ +import sys import collections import io import itertools @@ -915,6 +916,8 @@ class FunctionDef(LambdaFunctionMixin, lookup.LocalsDictNode, 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' |