From 9285fded89e7e9e9555cf2842aebac841a37eabb Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Fri, 14 Nov 2025 22:15:08 +0100 Subject: [PATCH] [python] PY-83029 fix compatibility inspection tests `testBreakInFinallyBlock` and `testReturnInFinallyBlock` were testing vs. latest language level, so apart from the compatibility warning (for which these tests are intended) - a corresponding syntax error was captured I made these tests to use a specific language level so they only verify the correctness of the compatibility inspection and introduced four tests in `PythonHighlightingTest` to capture the syntax error (cherry picked from commit 254570dc4d5022176590377eaf8ea6a08917937a) IJ-MR-182362 GitOrigin-RevId: fb9c92923820b370672451c5753ee24bdd5a4570 --- .../highlighting/breakInFinallyBlock.py | 5 ++++ .../breakInFinallyBlockBefore314.py | 5 ++++ .../highlighting/returnInFinallyBlock.py | 5 ++++ .../returnInFinallyBlockBefore314.py | 5 ++++ .../python/PythonHighlightingTest.java | 20 +++++++++++++ .../Py3CompatibilityInspectionTest.java | 29 +++++++++++-------- 6 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 python/testData/highlighting/breakInFinallyBlock.py create mode 100644 python/testData/highlighting/breakInFinallyBlockBefore314.py create mode 100644 python/testData/highlighting/returnInFinallyBlock.py create mode 100644 python/testData/highlighting/returnInFinallyBlockBefore314.py diff --git a/python/testData/highlighting/breakInFinallyBlock.py b/python/testData/highlighting/breakInFinallyBlock.py new file mode 100644 index 000000000000..0d809baaa540 --- /dev/null +++ b/python/testData/highlighting/breakInFinallyBlock.py @@ -0,0 +1,5 @@ +while True: + try: + print("a") + finally: + break \ No newline at end of file diff --git a/python/testData/highlighting/breakInFinallyBlockBefore314.py b/python/testData/highlighting/breakInFinallyBlockBefore314.py new file mode 100644 index 000000000000..bbc63509c8dd --- /dev/null +++ b/python/testData/highlighting/breakInFinallyBlockBefore314.py @@ -0,0 +1,5 @@ +while True: + try: + print("a") + finally: + break \ No newline at end of file diff --git a/python/testData/highlighting/returnInFinallyBlock.py b/python/testData/highlighting/returnInFinallyBlock.py new file mode 100644 index 000000000000..b28c3b8c528a --- /dev/null +++ b/python/testData/highlighting/returnInFinallyBlock.py @@ -0,0 +1,5 @@ +def foo(): + try: + pass + finally: + return \ No newline at end of file diff --git a/python/testData/highlighting/returnInFinallyBlockBefore314.py b/python/testData/highlighting/returnInFinallyBlockBefore314.py new file mode 100644 index 000000000000..e6fa44855cb7 --- /dev/null +++ b/python/testData/highlighting/returnInFinallyBlockBefore314.py @@ -0,0 +1,5 @@ +def foo(): + try: + pass + finally: + return \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java index b8aea21d8a27..521746e4778e 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -97,6 +97,26 @@ public class PythonHighlightingTest extends PyTestCase { doTest(LanguageLevel.PYTHON38, false, false); } + // PY-80237 + public void testBreakInFinallyBlockBefore314() { + doTest(LanguageLevel.PYTHON313, false, false); + } + + // PY-80237 + public void testBreakInFinallyBlock() { + doTest(LanguageLevel.PYTHON314, false, false); + } + + // PY-80237 + public void testReturnInFinallyBlockBefore314() { + doTest(LanguageLevel.PYTHON313, false, false); + } + + // PY-80237 + public void testReturnInFinallyBlock() { + doTest(LanguageLevel.PYTHON314, false, false); + } + public void testReturnWithArgumentsInGenerator() { doTest(); } diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java index 51334869ddf9..31efe20840aa 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java @@ -16,29 +16,34 @@ package com.jetbrains.python.inspections; import com.jetbrains.python.fixtures.PyInspectionTestCase; +import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; public class Py3CompatibilityInspectionTest extends PyInspectionTestCase { // PY-80237 public void testBreakInFinallyBlock() { - doTestByText(""" - while True: - try: - print("a") - finally: - break""" + runWithLanguageLevel( + LanguageLevel.PYTHON313, + () -> doTestByText(""" + while True: + try: + print("a") + finally: + break""") ); } // PY-80237 public void testReturnInFinallyBlock() { - doTestByText(""" - def foo(): - try: - pass - finally: - return""" + runWithLanguageLevel( + LanguageLevel.PYTHON313, + () -> doTestByText(""" + def foo(): + try: + pass + finally: + return""") ); }