Highlight module builtin methods as not allowed to be async (PY-28017)

This commit is contained in:
Semyon Proshev
2018-01-22 21:43:36 +03:00
parent 36f657d77b
commit 51eaba1aa2
3 changed files with 23 additions and 5 deletions
@@ -1,6 +1,7 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi.impl;
import com.google.common.collect.ImmutableMap;
import com.intellij.lang.ASTNode;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.extensions.Extensions;
@@ -744,13 +745,19 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Override
public boolean isAsyncAllowed() {
final LanguageLevel languageLevel = LanguageLevel.forElement(this);
if (languageLevel.isOlderThan(LanguageLevel.PYTHON35)) return false;
final String functionName = getName();
return languageLevel.isAtLeast(LanguageLevel.PYTHON35) && (
functionName == null ||
ArrayUtil.contains(functionName, PyNames.AITER, PyNames.ANEXT, PyNames.AENTER, PyNames.AEXIT, PyNames.CALL) ||
!PyNames.getBuiltinMethods(languageLevel).containsKey(functionName)
);
if (functionName == null ||
ArrayUtil.contains(functionName, PyNames.AITER, PyNames.ANEXT, PyNames.AENTER, PyNames.AEXIT, PyNames.CALL)) {
return true;
}
final ImmutableMap<String, PyNames.BuiltinDescription> builtinMethods =
asMethod() != null ? PyNames.getBuiltinMethods(languageLevel) : PyNames.getModuleBuiltinMethods(languageLevel);
return !builtinMethods.containsKey(functionName);
}
@Override
@@ -0,0 +1,6 @@
<error descr="function \"__getattr__\" cannot be async">async</error> def __getattr__(name):
pass
<error descr="function \"__dir__\" cannot be async">async</error> def __dir__():
pass
@@ -276,6 +276,11 @@ public class PythonHighlightingTest extends PyTestCase {
doTest(LanguageLevel.PYTHON35, true, false);
}
// PY-28017
public void testAsyncModuleBuiltinMethods() {
doTest(LanguageLevel.PYTHON37, true, false);
}
public void testImplicitOctLongInteger() {
doTest(LanguageLevel.PYTHON35, true, false);
}