diff --git a/python/testData/stubs/FunctionAnnotation.py b/python/testData/stubs/FunctionAnnotation.py new file mode 100644 index 000000000000..b9120c279bd1 --- /dev/null +++ b/python/testData/stubs/FunctionAnnotation.py @@ -0,0 +1,2 @@ +def func() -> int: + pass \ No newline at end of file diff --git a/python/testData/stubs/ParameterAnnotation.py b/python/testData/stubs/ParameterAnnotation.py new file mode 100644 index 000000000000..09b89554b7ff --- /dev/null +++ b/python/testData/stubs/ParameterAnnotation.py @@ -0,0 +1,2 @@ +def func(x: int): + pass \ No newline at end of file diff --git a/python/testData/stubs/VariableAnnotation.py b/python/testData/stubs/VariableAnnotation.py new file mode 100644 index 000000000000..7036172f9c55 --- /dev/null +++ b/python/testData/stubs/VariableAnnotation.py @@ -0,0 +1 @@ +x: int = ... \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyStubsTest.java b/python/testSrc/com/jetbrains/python/PyStubsTest.java index 42b8740e1d85..161572cd2e5b 100644 --- a/python/testSrc/com/jetbrains/python/PyStubsTest.java +++ b/python/testSrc/com/jetbrains/python/PyStubsTest.java @@ -726,4 +726,38 @@ public class PyStubsTest extends PyTestCase { assertNotParsed(external); }); } + + // PY-18116 + public void testParameterAnnotation() { + runWithLanguageLevel(LanguageLevel.PYTHON30, () -> { + final PyFile file = getTestFile(); + final PyFunction func = file.findTopLevelFunction("func"); + final PyNamedParameter param = func.getParameterList().findParameterByName("x"); + final String annotation = param.getAnnotationContent(); + assertEquals("int", annotation); + assertNotParsed(file); + }); + } + + // PY-18116 + public void testFunctionAnnotation() { + runWithLanguageLevel(LanguageLevel.PYTHON30, () -> { + final PyFile file = getTestFile(); + final PyFunction func = file.findTopLevelFunction("func"); + final String annotation = func.getAnnotationContent(); + assertEquals("int", annotation); + assertNotParsed(file); + }); + } + + // PY-18116 + public void testVariableAnnotation() { + runWithLanguageLevel(LanguageLevel.PYTHON36, () -> { + final PyFile file = getTestFile(); + final PyTargetExpression var = file.findTopLevelAttribute("x"); + final String annotation = var.getAnnotationContent(); + assertEquals("int", annotation); + assertNotParsed(file); + }); + } }