From 48148a5092291323909052f7ce2fdfa97272057c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rogalski?= Date: Sat, 28 Jan 2017 10:45:26 +0100 Subject: Mark __init_subclass__ as classmethod (#389) --- astroid/scoped_nodes.py | 3 +++ astroid/tests/unittest_scoped_nodes.py | 11 +++++++++++ 2 files changed, 14 insertions(+) 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): -- cgit v1.2.1