Skip to content
Snippets Groups Projects
Commit ac425e60 authored by Łukasz Rogalski's avatar Łukasz Rogalski Committed by GitHub
Browse files

Mark __init_subclass__ as classmethod (#388)

parent 61f49f4d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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):
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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'
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment