mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
PY-81861 Pattern matching for dataclasses - allow matching a subset of attributes
(cherry picked from commit 30a865e64cee7be630567b7d23223fc79eac9dbf) IJ-MR-168826 GitOrigin-RevId: 8383913015485a6b6e477131c47d502bb655dd30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0dfd1f65e4
commit
21e8b573a7
@@ -115,7 +115,7 @@ public class PyClassPatternImpl extends PyElementImpl implements PyClassPattern
|
||||
}
|
||||
|
||||
List<String> matchArgs = getMatchArgs(classType, context);
|
||||
if (matchArgs == null || matchArgs.size() > arguments.size()) return null;
|
||||
if (matchArgs == null || index >= matchArgs.size()) return null;
|
||||
|
||||
final PyTypedElement instanceAttribute = as(resolveTypeMember(classType, matchArgs.get(index), context), PyTypedElement.class);
|
||||
if (instanceAttribute == null) return null;
|
||||
|
||||
@@ -673,6 +673,26 @@ match x:
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-81861
|
||||
public void testDataclassPartialCapture() {
|
||||
doTestByText("""
|
||||
from dataclasses import dataclass
|
||||
from typing import assert_type
|
||||
|
||||
|
||||
@dataclass
|
||||
class A:
|
||||
a: int
|
||||
b: str
|
||||
|
||||
|
||||
x = A(1, "a")
|
||||
match x:
|
||||
case A(y):
|
||||
assert_type(y, int)
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-79832
|
||||
public void testMatchClassPatternSelfCaptureParameterized() {
|
||||
doTestByText("""
|
||||
|
||||
Reference in New Issue
Block a user