diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyDictLiteralCompletionContributor.kt b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyDictLiteralCompletionContributor.kt index 564e1d42fbf8..1d0f8e9d72de 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyDictLiteralCompletionContributor.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyDictLiteralCompletionContributor.kt @@ -53,7 +53,7 @@ private class DictLiteralCompletionProvider : CompletionProvider getMappedParameters(@NotNull PyExpression argument, @NotNull PyResolveContext resolveContext) { while (argument.getParent() instanceof PyParenthesizedExpression parenthesizedExpr) { argument = parenthesizedExpr; } - if (argument.getParent() instanceof PyKeywordArgument keywordArgument && keywordArgument.getValueExpression() == argument) { + if (argument.getParent() instanceof PyKeywordArgument keywordArgument) { + assert keywordArgument.getValueExpression() == argument; argument = keywordArgument; } @@ -771,7 +772,7 @@ public final class PyCallExpressionHelper { parent = parent.getParent(); } if (!(parent instanceof PyCallSiteExpression callSite)) { - return Collections.emptyList(); + return null; } PyExpression finalArgument = argument; diff --git a/python/testData/completion/literalType/nestedParenthesisInAssigment.py b/python/testData/completion/literalType/nestedParenthesisInAssigment.py new file mode 100644 index 000000000000..b2740f7d1f8a --- /dev/null +++ b/python/testData/completion/literalType/nestedParenthesisInAssigment.py @@ -0,0 +1,5 @@ +from typing import Literal + + +item: Literal[Literal[Literal["0", 2], "acc"], "5", None] +item=((())) \ No newline at end of file diff --git a/python/testData/completion/literalType/nestedParenthesisInCallExpression.py b/python/testData/completion/literalType/nestedParenthesisInCallExpression.py new file mode 100644 index 000000000000..c6aea8f8d119 --- /dev/null +++ b/python/testData/completion/literalType/nestedParenthesisInCallExpression.py @@ -0,0 +1,8 @@ +from typing import Literal + + +def f(x, y: Literal[Literal["abb"], "bac"]): + pass + + +f(1, ((("")))) \ No newline at end of file diff --git a/python/testData/completion/literalType/nestedParenthesisInKeywordArgumentValue.py b/python/testData/completion/literalType/nestedParenthesisInKeywordArgumentValue.py new file mode 100644 index 000000000000..0f2816a9c2d1 --- /dev/null +++ b/python/testData/completion/literalType/nestedParenthesisInKeywordArgumentValue.py @@ -0,0 +1,8 @@ +from typing import Literal + + +def f(x: Literal[Literal[Literal[1, "-1"], "foo"], "6", None]) -> None: + pass + + +f(x=(((())))) diff --git a/python/testData/completion/literalType/nestedParenthesisInSubscriptionExpression.py b/python/testData/completion/literalType/nestedParenthesisInSubscriptionExpression.py new file mode 100644 index 000000000000..f8369e55de17 --- /dev/null +++ b/python/testData/completion/literalType/nestedParenthesisInSubscriptionExpression.py @@ -0,0 +1,8 @@ +from typing import Literal + +class A: + def __getitem__(self, item: Literal[Literal[Literal["1", "2"], "foo"], "5", None]) -> str: + pass + + +A()[((((""))))] \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyLiteralTypeCompletionTest.kt b/python/testSrc/com/jetbrains/python/PyLiteralTypeCompletionTest.kt index b89508353168..0810b1281ae4 100644 --- a/python/testSrc/com/jetbrains/python/PyLiteralTypeCompletionTest.kt +++ b/python/testSrc/com/jetbrains/python/PyLiteralTypeCompletionTest.kt @@ -11,18 +11,38 @@ class PyLiteralTypeCompletionTest : PyTestCase() { doTestCompletionVariantsContains("inCallExpression.py", "\"1\"", "\"2\"", "\"foo\"", "\"5\"") } + // PY-72661 + fun testNestedParenthesisInCallExpression() { + myFixture.testCompletionVariants("nestedParenthesisInCallExpression.py", "abb", "bac") + } + fun testInKeywordArgument() { doTestCompletionVariantsContains("inKeywordArgument.py", "\"3\"", "\"foo\"", "\"5\"") } + // PY-72661 + fun testNestedParenthesisInKeywordArgumentValue() { + doTestCompletionVariantsContains("nestedParenthesisInKeywordArgumentValue.py", "\"-1\"", "\"foo\"", "\"6\"") + } + fun testInSubscriptionExpression() { doTestCompletionVariantsContains("inSubscriptionExpression.py", "\"1\"", "\"foo\"", "\"5\"") } + // PY-72661 + fun testNestedParenthesisInSubscriptionExpression() { + myFixture.testCompletionVariants("nestedParenthesisInSubscriptionExpression.py", "1", "2", "foo", "5") + } + fun testInAssigment() { doTestCompletionVariantsContains("inAssignment.py", "\"1\"", "\"3\"", "\"foo\"", "\"5\"") } + // PY-72661 + fun testNestedParenthesisInAssigment() { + doTestCompletionVariantsContains("nestedParenthesisInAssigment.py", "\"0\"", "\"acc\"", "\"5\"") + } + fun testInDoubleQuotedString() { myFixture.testCompletionVariants("inDoubleQuotedString.py", "bar", "foo") }