mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
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
This commit is contained in:
@@ -432,8 +432,17 @@ public class PyNames {
|
||||
.put(ANEXT, _only_self_descr)
|
||||
.build();
|
||||
|
||||
public static final ImmutableMap<String, BuiltinDescription> PY36_BUILTIN_METHODS = ImmutableMap.<String, BuiltinDescription>builder()
|
||||
.putAll(PY35_BUILTIN_METHODS)
|
||||
.put("__init_subclass__", new BuiltinDescription("(cls, **kwargs)"))
|
||||
.put("__set_name__", new BuiltinDescription("(self, owner, name)"))
|
||||
.build();
|
||||
|
||||
public static ImmutableMap<String, BuiltinDescription> 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)) {
|
||||
|
||||
@@ -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<caret>");
|
||||
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<caret>");
|
||||
myFixture.checkResult("class Cl(object):\n" +
|
||||
" def __set_name__(self, owner, name):");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/completion";
|
||||
|
||||
Reference in New Issue
Block a user