mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Removed recent change in dataclass_transform
handling. Dataclass properties should not be inherited from base classes after all. See https://discuss.python.org/t/dataclass-transform-inheriting-class-doesnt-recognize-kw-only-true-from-parent-class/55734/2.
This commit is contained in:
parent
cbd189a29f
commit
a03eb8492e
@ -17071,28 +17071,6 @@ export function createTypeEvaluator(
|
||||
// Determine whether this class derives from (or has a metaclass) that imbues
|
||||
// it with dataclass-like behaviors. If so, we'll apply those here.
|
||||
let dataClassBehaviors: DataClassBehaviors | undefined;
|
||||
|
||||
// If this class has not already received its dataclass behaviors from a
|
||||
// decorator and is inheriting from a class that has dataclass behaviors,
|
||||
// apply those inherited behaviors to this class.
|
||||
if (!classType.details.dataClassBehaviors) {
|
||||
for (const mroClass of classType.details.mro) {
|
||||
if (!isClass(mroClass)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ClassType.isSameGenericClass(mroClass, classType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mroClass.details.dataClassBehaviors) {
|
||||
dataClassBehaviors = mroClass.details.dataClassBehaviors;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!dataClassBehaviors) {
|
||||
if (isInstantiableClass(effectiveMetaclass) && effectiveMetaclass.details.classDataClassTransform) {
|
||||
dataClassBehaviors = effectiveMetaclass.details.classDataClassTransform;
|
||||
} else {
|
||||
@ -17108,7 +17086,6 @@ export function createTypeEvaluator(
|
||||
dataClassBehaviors = (baseClassDataTransform as ClassType).details.classDataClassTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataClassBehaviors) {
|
||||
applyDataClassClassBehaviorOverrides(
|
||||
|
@ -1,29 +0,0 @@
|
||||
# This sample tests the case where a dataclass inherits a dataclass
|
||||
# behavior (like kw_only) from its parent class.
|
||||
|
||||
from typing import dataclass_transform
|
||||
|
||||
|
||||
@dataclass_transform()
|
||||
class ModelMeta(type):
|
||||
pass
|
||||
|
||||
|
||||
class ModelBase(metaclass=ModelMeta):
|
||||
def __init_subclass__(cls, kw_only: bool = False) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class Base(ModelBase, kw_only=True):
|
||||
pass
|
||||
|
||||
|
||||
class Model(Base):
|
||||
a: str | None = None
|
||||
b: int
|
||||
|
||||
|
||||
Model(b=0)
|
||||
|
||||
# This should generate an error because of kw_only.
|
||||
Model("", 1)
|
@ -416,12 +416,6 @@ test('DataclassTransform4', () => {
|
||||
TestUtils.validateResults(analysisResults, 2);
|
||||
});
|
||||
|
||||
test('DataclassTransform5', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['dataclassTransform5.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
test('Async1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['async1.py']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user