From dff84e5cf524c90b3a1a8dd39eb79b736c487308 Mon Sep 17 00:00:00 2001 From: "aleksei.kniazev" Date: Wed, 6 Feb 2019 14:16:23 +0300 Subject: [PATCH] added return type annotation completion for method overriding --- .../completion/PySuperMethodCompletionContributor.java | 3 +++ .../testData/completion/superMethodWithAnnotation.after.py | 7 +++++++ python/testData/completion/superMethodWithAnnotation.py | 7 +++++++ .../testSrc/com/jetbrains/python/PythonCompletionTest.java | 4 ++++ 4 files changed, 21 insertions(+) create mode 100644 python/testData/completion/superMethodWithAnnotation.after.py create mode 100644 python/testData/completion/superMethodWithAnnotation.py diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PySuperMethodCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PySuperMethodCompletionContributor.java index 213b6fbde809..4d276f1f0a78 100644 --- a/python/src/com/jetbrains/python/codeInsight/completion/PySuperMethodCompletionContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/completion/PySuperMethodCompletionContributor.java @@ -66,6 +66,9 @@ public class PySuperMethodCompletionContributor extends CompletionContributor { for (PyFunction superMethod : ancestor.getMethods()) { if (!seenNames.contains(superMethod.getName())) { String text = superMethod.getName() + superMethod.getParameterList().getText(); + if (languageLevel.isAtLeast(LanguageLevel.PYTHON35) && superMethod.getAnnotation() != null) { + text += " " + superMethod.getAnnotation().getText(); + } LookupElementBuilder element = LookupElementBuilder.create(text); result.addElement(TailTypeDecorator.withTail(element, TailType.CASE_COLON)); seenNames.add(superMethod.getName()); diff --git a/python/testData/completion/superMethodWithAnnotation.after.py b/python/testData/completion/superMethodWithAnnotation.after.py new file mode 100644 index 000000000000..c498d16c9260 --- /dev/null +++ b/python/testData/completion/superMethodWithAnnotation.after.py @@ -0,0 +1,7 @@ +class Parent: + def overridable_method(param: str) -> Dict[str, str]: + pass + + +class Child(Parent): + def overridable_method(param: str) -> Dict[str, str]: \ No newline at end of file diff --git a/python/testData/completion/superMethodWithAnnotation.py b/python/testData/completion/superMethodWithAnnotation.py new file mode 100644 index 000000000000..82a7ad9e3248 --- /dev/null +++ b/python/testData/completion/superMethodWithAnnotation.py @@ -0,0 +1,7 @@ +class Parent: + def overridable_method(param: str) -> Dict[str, str]: + pass + + +class Child(Parent): + def over \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java index dc5a1b4860fa..00679715dbdd 100644 --- a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java +++ b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java @@ -314,6 +314,10 @@ public class PythonCompletionTest extends PyTestCase { doTest(); } + public void testSuperMethodWithAnnotation() { + runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + } + public void testLocalVarInDictKey() { // PY-2558 doTest(); }