diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingTypeProvider.java b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingTypeProvider.java index 1cbf488c2dcd..f2df1e78668b 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingTypeProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingTypeProvider.java @@ -546,8 +546,8 @@ public class PyTypingTypeProvider extends PyTypeProviderBase { return candidates .map(x -> getTypeFromTargetExpressionAnnotation(x, context)) .nonNull() - .map(Ref::get) .findFirst() + .map(Ref::get) .orElse(null); } } diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index ebb41615e01c..3b7f8fcb2c07 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -777,6 +777,17 @@ public class PyTypingTest extends PyTestCase { "expr = x"); } + // PY-16412 + public void testLocalVariableAnnotationAheadOfTimeExplicitAny() { + doTest("Any", + "from typing import Any\n" + + "\n" + + "def func(x):\n" + + " var: Any\n" + + " var = x\n" + + " expr = var\n"); + } + // PY-21864 public void testClassAttributeAnnotationAheadOfTimeInAnotherFile() { doMultiFileStubAwareTest("int",