[python] PY-79930 don't fold __future__ imports

Merge-request: IJ-MR-171486
Merged-by: Morgan Bartholomew <morgan.bartholomew@jetbrains.com>

GitOrigin-RevId: 968e8d7c03dd7e46ff55316cffd07e7e2a9c7b54
This commit is contained in:
Morgan Bartholomew
2025-08-18 12:09:41 +00:00
committed by intellij-monorepo-bot
parent 787d1f6d6c
commit 5b3cb745e0
4 changed files with 30 additions and 3 deletions
@@ -110,9 +110,10 @@ open class PythonFoldingBuilder : CustomFoldingBuilder(), DumbAware {
val elementType = node.elementType
if (node.psi is PyAstFile) {
val imports = (node.psi as PyAstFile).importBlock
if (imports.size > 1) {
val firstImport: PyAstImportStatementBase = imports[0]
val lastImport: PyAstImportStatementBase = imports[imports.size - 1]
val firstIndex = imports.takeWhile { (it as? PyAstFromImportStatement)?.isFromFuture == true }.size
if (imports.size - firstIndex > 1) {
val firstImport: PyAstImportStatementBase = imports[firstIndex]
val lastImport: PyAstImportStatementBase = imports.last()
descriptors.add(FoldingDescriptor(firstImport, TextRange(firstImport.textRange.startOffset,
lastImport.textRange.endOffset)))
}
+9
View File
@@ -0,0 +1,9 @@
"""This is a module-level docstring."""
from __future__ import annotations
from __future__ import another_one
<fold text='import ...'>import os
import sys</fold>
print(os, sys)
@@ -0,0 +1,7 @@
"""This is a module-level docstring."""
from __future__ import annotations
import os
print(os.path)
@@ -245,4 +245,14 @@ public class PyFoldingTest extends PyTestCase {
public void testMatchFolding() {
doTest();
}
// PY-79930
public void testFutureImport() {
doTest();
}
// PY-79930
public void testFutureImportWithOneImport() {
doTest();
}
}