Updated logic for dataclass_transform to handle recent clarification in PEP 681 for cases where one or more overloads are decorated with dataclass_transform.

This commit is contained in:
Eric Traut 2022-04-01 09:52:41 -07:00
parent 139139a9a2
commit dc153cb35d

View File

@ -738,7 +738,13 @@ export function getDataclassDecoratorBehaviors(type: Type): DataClassBehaviors |
if (isFunction(type)) {
functionType = type;
} else if (isOverloadedFunction(type)) {
functionType = type.overloads[0];
// Find the first overload or implementation that contains a
// dataclass_transform decorator. If more than one have such a decorator,
// only the first one will be honored, as per PEP 681.
functionType =
type.overloads.find((overload) => {
overload.details.decoratorDataClassBehaviors !== undefined;
}) ?? type.overloads[0];
}
if (!functionType) {