PY-76149 Support descriptor types as annotations for dataclass fields

(cherry picked from commit 78a127e1a0083ece810ad996124ad6ea65887da2)

GitOrigin-RevId: 0c33fe51f5f13116f773577056317c537cbc83ef
This commit is contained in:
Daniil Kalinin
2024-10-02 18:52:05 +03:00
committed by intellij-monorepo-bot
parent 4ad6f08f45
commit c653a43cab
4 changed files with 112 additions and 0 deletions

View File

@@ -254,6 +254,12 @@ class PyDataclassTypeProvider : PyTypeProviderBase() {
if (type is PyCollectionType && type.classQName == Dataclasses.DATACLASSES_INITVAR) {
return type.elementTypes.firstOrNull()
}
if (type is PyClassLikeType) {
val expectedConstructorArgumentTypeRef = PyDescriptorTypeUtil.getExpectedValueTypeForDunderSet(field, type, context)
if (expectedConstructorArgumentTypeRef != null) {
return Ref.deref(expectedConstructorArgumentTypeRef)
}
}
if (type == null && dataclassType.asPredefinedType == PyDataclassParameters.PredefinedType.ATTRS) {
methodDecoratedAsAttributeDefault(cls, field.name)