From 2d7e9c9b72b0ee93c412ee106f25de268751895c Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Wed, 14 Aug 2019 10:23:07 +0900 Subject: [PATCH] support ellipsis --- src/com/koxudaxi/pydantic/PydanticTypeProvider.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt b/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt index fa7d4fbb..65fec9ad 100644 --- a/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt +++ b/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt @@ -27,7 +27,8 @@ class PydanticTypeProvider : PyTypeProviderBase() { cls .findClassAttribute(name, false, context) ?.let { - return Ref.create(getTypeForParameter(it, context)) } + return Ref.create(getTypeForParameter(it, context)) + } for (ancestor in cls.getAncestorClasses(context)) { ancestor @@ -134,7 +135,7 @@ class PydanticTypeProvider : PyTypeProviderBase() { when { annotation.qualifier?.text == "Optional" -> return ellipsis - annotation.qualifier?.text == "Union" -> for (child in annotation.children){ + annotation.qualifier?.text == "Union" -> for (child in annotation.children) { if (child is PyTupleExpression) { for (type in child.children) { if (type is PyNoneLiteralExpression) { @@ -146,7 +147,11 @@ class PydanticTypeProvider : PyTypeProviderBase() { } return value } - field.hasAssignedValue() -> return ellipsis + field.hasAssignedValue() -> { + return if (field.findAssignedValue()!!.text == "...") { + null + } else ellipsis + } else -> return null } } else if (fieldStub.hasDefault() || fieldStub.hasDefaultFactory()) {