From 4e7181a473d514ce5e3f9f1dde8cd63e29c96312 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 11 Sep 2025 17:35:48 +0300 Subject: [PATCH] PY-80002 Remove excessive version checks in PyResolveUtil.allowForwardReferences `from __future__ import annotations` is not available in Python < 3.7, and in earlier versions such import itself should be highlighted, and using type parameter lists in Python < 3.12 is already reported. GitOrigin-RevId: 18075131473fb5cee8a47ab259cfdc753889892e --- .../com/jetbrains/python/psi/resolve/PyResolveUtil.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java b/python/python-psi-impl/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java index 6683e3d06162..20a9d347a779 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java @@ -424,15 +424,12 @@ public final class PyResolveUtil { // Forward references are allowed in annotations according to PEP 563 PsiFile file = element.getContainingFile(); if (file instanceof PyFile pyFile) { - LanguageLevel languageLevel = pyFile.getLanguageLevel(); - boolean nonEagerEvaluationEnabled = - (languageLevel.isAtLeast(LanguageLevel.PYTHON37) && pyFile.hasImportFromFuture(FutureFeature.ANNOTATIONS)) - || languageLevel.isAtLeast(LanguageLevel.PYTHON314); + boolean nonEagerEvaluationEnabled = pyFile.hasImportFromFuture(FutureFeature.ANNOTATIONS) || + pyFile.getLanguageLevel().isAtLeast(LanguageLevel.PYTHON314); boolean insideAnnotation = PsiTreeUtil.getParentOfType(element, PyAnnotation.class) != null; if (insideAnnotation && nonEagerEvaluationEnabled) return true; - boolean isReferenceFromTypeParameterList = languageLevel.isAtLeast(LanguageLevel.PYTHON312) && - PsiTreeUtil.getParentOfType(element, PyTypeParameter.class, true) != null; + boolean isReferenceFromTypeParameterList = PsiTreeUtil.getParentOfType(element, PyTypeParameter.class, true) != null; if (isReferenceFromTypeParameterList) return true; } return false;