From aee3680c25e75a17afa3bffe38f3536ec498ff6e Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Sat, 24 Sep 2016 21:08:46 +0300 Subject: [PATCH] PY-20768 Fixed: Support special attributes of PEP 487: simpler customization of class creation Create PY36_BUILTIN_METHODS in PyNames and add __init_subclass__, __set_name__ to it --- .../src/com/jetbrains/python/PyNames.java | 11 +++++++++- .../python/PythonCompletionTest.java | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index 623096171a8d..f3f787a39390 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -432,8 +432,17 @@ public class PyNames { .put(ANEXT, _only_self_descr) .build(); + public static final ImmutableMap PY36_BUILTIN_METHODS = ImmutableMap.builder() + .putAll(PY35_BUILTIN_METHODS) + .put("__init_subclass__", new BuiltinDescription("(cls, **kwargs)")) + .put("__set_name__", new BuiltinDescription("(self, owner, name)")) + .build(); + public static ImmutableMap getBuiltinMethods(LanguageLevel level) { - if (level.isAtLeast(LanguageLevel.PYTHON35)) { + if (level.isAtLeast(LanguageLevel.PYTHON36)) { + return PY36_BUILTIN_METHODS; + } + else if (level.isAtLeast(LanguageLevel.PYTHON35)) { return PY35_BUILTIN_METHODS; } else if (level.isAtLeast(LanguageLevel.PYTHON30)) { diff --git a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java index 8e196d324bce..d64a6be42a1e 100644 --- a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java +++ b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java @@ -939,6 +939,28 @@ public class PythonCompletionTest extends PyTestCase { doTest(); } + // PY-20768 + public void testInitSubclassBuiltinMethod() { + runWithLanguageLevel(LanguageLevel.PYTHON36, + () -> { + doTestByText("class Cl(object):\n" + + " def __init_su"); + myFixture.checkResult("class Cl(object):\n" + + " def __init_subclass__(cls, **kwargs):"); + }); + } + + // PY-20768 + public void testSetNameBuiltinMethod() { + runWithLanguageLevel(LanguageLevel.PYTHON36, + () -> { + doTestByText("class Cl(object):\n" + + " def __set_n"); + myFixture.checkResult("class Cl(object):\n" + + " def __set_name__(self, owner, name):"); + }); + } + @Override protected String getTestDataPath() { return super.getTestDataPath() + "/completion";