diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 740fabd4..b8a0eda6 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -5,12 +5,16 @@ Koudai Aono @koxudaxi version 0.1.5 -

BugFixes

+

Features

+ +

BugFixes

version 0.1.4

-

BugFixes

+

BugFixes

diff --git a/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt b/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt index 0c72bc56..7927841e 100644 --- a/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt +++ b/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt @@ -62,22 +62,26 @@ class PydanticTypeCheckerInspection : PyTypeCheckerInspection() { } private fun getTypeFromTypeMap(getTypeMap: (project: Project) -> (MutableMap>), typeForParameter: PyType, cache: MutableMap): PyType? { - return when { - cache.containsKey(typeForParameter) -> { - cache[typeForParameter] - } + if (cache.containsKey(typeForParameter)) { + return cache[typeForParameter] + } + + val newType = when (typeForParameter) { + is PyCollectionType -> + PyCollectionTypeImpl(typeForParameter.pyClass, typeForParameter.isDefinition, typeForParameter.elementTypes.mapNotNull { + getTypeFromTypeMap(getTypeMap, it, cache) + }) else -> { val project = holder!!.project - val typeMap = getTypeMap(project) - val unionType = PyUnionType.union(getPyClassTypeByPyTypes(typeForParameter).toSet().flatMap { type -> - typeMap[type.classQName]?.mapNotNull { + PyUnionType.union(getPyClassTypeByPyTypes(typeForParameter).toSet().flatMap { type -> + getTypeMap(project)[type.classQName]?.mapNotNull { createPyClassTypeImpl(it, project, myTypeEvalContext) } as? List ?: listOf() }) - cache[typeForParameter] = unionType - unionType } } + cache[typeForParameter] = newType + return newType } private fun analyzeCallee(callSite: PyCallSiteExpression, mapping: PyArgumentsMapping) { diff --git a/testData/typecheckerinspection/parsableTypeCollection.py b/testData/typecheckerinspection/parsableTypeCollection.py new file mode 100644 index 00000000..c579c94f --- /dev/null +++ b/testData/typecheckerinspection/parsableTypeCollection.py @@ -0,0 +1,16 @@ +from builtins import * +from typing import Union, List + +from pydantic import BaseModel + + +class A(BaseModel): + a: List[str] + b: List[List[str]] + +a_int: List[int] = [int('123')] +a_str: List[str] = [str('123')] +b_int: List[List[int]] = [[int('123')]] +b_str: List[List[str]] = [[str('123')]] +A(a=a_str, b=b_str) +A(a=a_int, b=b_int) diff --git a/testSrc/com/koxudaxi/pydantic/PydanticTypeCheckerInspectionTest.kt b/testSrc/com/koxudaxi/pydantic/PydanticTypeCheckerInspectionTest.kt index 80b1bcde..abeeae1a 100644 --- a/testSrc/com/koxudaxi/pydantic/PydanticTypeCheckerInspectionTest.kt +++ b/testSrc/com/koxudaxi/pydantic/PydanticTypeCheckerInspectionTest.kt @@ -15,6 +15,11 @@ open class PydanticTypeCheckerInspectionTest : PydanticInspectionBase() { pydanticConfigService.parsableTypeMap["builtins.str"] = arrayListOf("builtins.int") doTest() } + fun testParsableTypeCollection() { + val pydanticConfigService = PydanticConfigService.getInstance(myFixture!!.project) + pydanticConfigService.parsableTypeMap["builtins.str"] = arrayListOf("builtins.int") + doTest() + } fun testParsableTypeWeakWarning() { val pydanticConfigService = PydanticConfigService.getInstance(myFixture!!.project) pydanticConfigService.parsableTypeMap["builtins.str"] = arrayListOf("builtins.int")