mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-60352 Consider overriding attributes when checking dataclass attributes with default values with inheritance
(cherry picked from commit 9a3332cb0f5e0ef4af8ee891c442b6fe4076ea0e) IJ-MR-192626 GitOrigin-RevId: 781f98ea792933e93e7e960ac139407efe1a0261
This commit is contained in:
committed by
intellij-monorepo-bot
parent
23607e5e37
commit
ebc3f5f250
+10
-4
@@ -37,23 +37,29 @@ class PyNamedTupleInspection : PyInspection() {
|
||||
if ((fieldsProcessor == null || fieldsProcessor.fieldsWithoutDefaultValue.isEmpty()) && !checkInheritedOrder) return
|
||||
|
||||
val ancestors = cls.getAncestorClasses(context)
|
||||
val ancestorKinds = ancestors.map {
|
||||
if (!classFieldsFilter(it)) {
|
||||
val attributeNames = mutableSetOf<String>()
|
||||
val ancestorKinds = mutableListOf<Ancestor>()
|
||||
for (ancestor in ancestors.reversed()) {
|
||||
val kind = if (!classFieldsFilter(ancestor)) {
|
||||
Ancestor.FILTERED
|
||||
}
|
||||
else {
|
||||
val processor = processFields(it, fieldsFilter, hasAssignedValue, context)
|
||||
val processor = processFields(ancestor, fieldsFilter, hasAssignedValue, context)
|
||||
if (processor.fieldsWithDefaultValue.isNotEmpty()) {
|
||||
Ancestor.HAS_FIELD_WITH_DEFAULT_VALUE
|
||||
}
|
||||
else if (processor.fieldsWithoutDefaultValue.isNotEmpty()) {
|
||||
else if (processor.fieldsWithoutDefaultValue.isNotEmpty() && !attributeNames.containsAll(processor.fieldsWithoutDefaultValue.map { field -> field.name })) {
|
||||
Ancestor.HAS_FIELD_WITHOUT_DEFAULT_VALUE
|
||||
}
|
||||
else {
|
||||
Ancestor.FILTERED
|
||||
}
|
||||
}
|
||||
|
||||
ancestorKinds.add(kind)
|
||||
attributeNames.addAll(ancestor.classAttributes.mapNotNull { attribute -> attribute.name })
|
||||
}
|
||||
ancestorKinds.reverse()
|
||||
|
||||
if (checkInheritedOrder) {
|
||||
var seenAncestorHavingFieldWithDefaultValue: PyClass? = null
|
||||
|
||||
@@ -420,6 +420,31 @@ public class PyDataclassInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-60352
|
||||
public void testDataclassMultipleInheritanceAttributeWithDefault() {
|
||||
doTestByText("""
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Parent1:
|
||||
number: int
|
||||
default: int = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class Parent2:
|
||||
number: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class Child(Parent2, Parent1):
|
||||
pass
|
||||
|
||||
|
||||
Child(number=1)""");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doTest() {
|
||||
myFixture.copyDirectoryToProject("packages/attr", "attr");
|
||||
|
||||
Reference in New Issue
Block a user