PY-45368 Fixed completing 'None' in type annotations

GitOrigin-RevId: fc7e7ff0a03ce41373bac2eedbf3e8b7aaa2ce4d
This commit is contained in:
Andrey Vlasovskikh
2021-03-24 14:53:13 +00:00
committed by intellij-monorepo-bot
parent 848266ad5c
commit 65dee450b8
6 changed files with 30 additions and 0 deletions
@@ -323,6 +323,9 @@ public class PyKeywordCompletionContributor extends CompletionContributor implem
private static final PsiElementPattern.Capture<PsiElement> IN_ELSE_BODY_OF_TRY =
psiElement().inside(psiElement(PyStatementList.class).inside(psiElement(PyElsePart.class).inside(PyTryExceptStatement.class)));
private static final PsiElementPattern.Capture<PsiElement> IN_ANNOTATION =
psiElement().inside(psiElement(PyAnnotation.class));
private static final PsiElementPattern.Capture<PsiElement> AFTER_IF = afterStatement(psiElement(PyIfStatement.class).withLastChild(
psiElement(PyIfPart.class)));
private static final PsiElementPattern.Capture<PsiElement> AFTER_TRY = afterStatement(psiElement(PyTryExceptStatement.class));
@@ -644,6 +647,11 @@ public class PyKeywordCompletionContributor extends CompletionContributor implem
.and(PY35)
.afterLeaf(psiElement().withElementType(PyTokenTypes.IDENTIFIER).withText(PyNames.ASYNC)),
new PyKeywordCompletionProvider(PyNames.DEF, PyNames.WITH, PyNames.FOR));
extend(CompletionType.BASIC,
psiElement()
.withLanguage(PythonLanguage.getInstance())
.and(IN_ANNOTATION),
new PyKeywordCompletionProvider(TailType.NONE, PyNames.NONE));
}
private void addAs() {
@@ -0,0 +1,5 @@
from typing import Union
def foo(x: Union[int, None]):
pass
@@ -0,0 +1,5 @@
from typing import Union
def foo(x: Union[int, Non<caret>]):
pass
@@ -0,0 +1 @@
def foo() -> None
@@ -0,0 +1 @@
def foo() -> Non<caret>
@@ -248,4 +248,14 @@ public class PythonKeywordCompletionTest extends PyTestCase {
public void testNoForAndYieldInCommentContext() {
assertDoesntContain(doTestByTestName(), "for", "yield");
}
// PY-45368
public void testNoneInParameterAnnotation() {
doTest();
}
// PY-45368
public void testNoneInReturnAnnotation() {
doTest();
}
}