PY-83900 Inspect Code consumes 100% CPU and takes unusually long on specific simple file

(cherry picked from commit 81973d162072c94b4d7201dffc68d43669f449a3)

IJ-MR-174807

GitOrigin-RevId: 7d6563db8b59c05f6ecc20abe929ce6771ece825
This commit is contained in:
Aleksandr.Govenko
2025-09-08 03:24:28 +02:00
committed by intellij-monorepo-bot
parent e89761784e
commit a1ea38b4b9
12 changed files with 55 additions and 49 deletions

View File

@@ -4,7 +4,7 @@ package com.jetbrains.python.psi;
import com.jetbrains.python.ast.PyAstCaseClause;
import org.jetbrains.annotations.Nullable;
public interface PyCaseClause extends PyAstCaseClause, PyStatementPart, PyCaptureContext {
public interface PyCaseClause extends PyAstCaseClause, PyStatementPart {
@Override
default @Nullable PyPattern getPattern() {
return (PyPattern)PyAstCaseClause.super.getPattern();

View File

@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Set;
public interface PyClassPattern extends PyAstClassPattern, PyPattern, PyCaptureContext {
public interface PyClassPattern extends PyAstClassPattern, PyPattern {
Set<String> SPECIAL_BUILTINS = Set.of(
"bool", "bytearray", "bytes", "dict", "float", "frozenset", "int", "list", "set", "str", "tuple");

View File

@@ -3,4 +3,4 @@ package com.jetbrains.python.psi
import com.jetbrains.python.ast.PyAstMappingPattern
interface PyMappingPattern : PyAstMappingPattern, PyPattern, PyCaptureContext
interface PyMappingPattern : PyAstMappingPattern, PyPattern

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi
import com.intellij.psi.util.findParentOfType
import com.jetbrains.python.ast.PyAstPattern
import com.jetbrains.python.psi.types.PyType
import com.jetbrains.python.psi.types.TypeEvalContext
@@ -40,38 +39,3 @@ interface PyPattern : PyAstPattern, PyTypedElement {
return true
}
}
interface PyCaptureContext : PyElement {
fun getCaptureTypeForChild(pattern: PyPattern, context: TypeEvalContext): PyType?
companion object {
/**
* Determines what type this pattern would have if it was a capture pattern (like a bare name or _).
*
* In pattern matching, a capture pattern takes on the type of the entire matched expression,
* regardless of any specific pattern constraints.
*
* For example:
* ```python
* x: int | str
* match x:
* case a: # This is a capture pattern
* # Here 'a' has type int | str
* case str(): # This is a class pattern
* # Capture type: int | str (same as what 'case a:' would get)
* # Regular getType: str
*
* y: int
* match y:
* case str() as a:
* # Capture type: int (same as what 'case a:' would get)
* # Regular getType: intersect(int, str) (just 'str' for now)
* ```
* @see PyPattern#getType(TypeEvalContext, TypeEvalContext.Key)
*/
@JvmStatic
fun getCaptureType(pattern: PyPattern, context: TypeEvalContext): PyType? {
return pattern.findParentOfType<PyCaptureContext>()?.getCaptureTypeForChild(pattern, context)
}
}
}

View File

@@ -4,7 +4,7 @@ package com.jetbrains.python.psi
import com.jetbrains.python.ast.PyAstSequencePattern
import com.jetbrains.python.ast.findChildrenByClass
interface PySequencePattern : PyAstSequencePattern, PyPattern, PyCaptureContext {
interface PySequencePattern : PyAstSequencePattern, PyPattern {
val elements: List<PyPattern>
get() = findChildrenByClass(PyPattern::class.java).toList()
}