diff options
author | Ćukasz Rogalski <rogalski.91@gmail.com> | 2017-01-30 22:01:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-30 22:01:57 +0100 |
commit | ac425e60a2c243eaf0b41ba1eb33b84a49d11eb7 (patch) | |
tree | 5dca9c5c887130845e624f52ba0fa752571c9410 | |
parent | 61f49f4dee7cda2976866ea1441973c4ab55dda6 (diff) | |
download | astroid-git-2.0.tar.gz |
Mark __init_subclass__ as classmethod (#388)2.0.experimental2.0
-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' |