From 1e161dd5d266f5e28792999dcce26112fdf923e7 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Thu, 28 Nov 2019 01:41:21 +0900 Subject: [PATCH] Support positional arguments for dataclasses (#91) * fix dataclass inspection --- resources/META-INF/plugin.xml | 3 ++- src/com/koxudaxi/pydantic/PydanticInspection.kt | 2 +- testData/inspection/acceptsOnlyKeywordArguments.py | 9 ++++++++- .../acceptsOnlyKeywordArgumentsSingleStarArgument.py | 9 +++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 161958fd..7993cce5 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -5,8 +5,9 @@ Koudai Aono @koxudaxi version 0.0.28 -

BugFixes

+

Features, BugFixes

version 0.0.27

diff --git a/src/com/koxudaxi/pydantic/PydanticInspection.kt b/src/com/koxudaxi/pydantic/PydanticInspection.kt index ca866297..620cc7fd 100644 --- a/src/com/koxudaxi/pydantic/PydanticInspection.kt +++ b/src/com/koxudaxi/pydantic/PydanticInspection.kt @@ -66,7 +66,7 @@ class PydanticInspection : PyInspection() { private fun inspectPydanticModelCallableExpression(pyCallExpression: PyCallExpression) { val pyClass = getPyClassByPyCallExpression(pyCallExpression, myTypeEvalContext) ?: return - if (!isPydanticModel(pyClass, myTypeEvalContext)) return + if (!isSubClassOfPydanticBaseModel(pyClass, myTypeEvalContext) || isPydanticBaseModel(pyClass)) return if ((pyCallExpression.callee as? PyReferenceExpressionImpl)?.isQualified == true) return pyCallExpression.arguments .filterNot { it is PyKeywordArgument || (it as? PyStarArgumentImpl)?.isKeyword == true } diff --git a/testData/inspection/acceptsOnlyKeywordArguments.py b/testData/inspection/acceptsOnlyKeywordArguments.py index 189bab0d..11c31459 100644 --- a/testData/inspection/acceptsOnlyKeywordArguments.py +++ b/testData/inspection/acceptsOnlyKeywordArguments.py @@ -1,8 +1,15 @@ from pydantic import BaseModel - +from pydantic.dataclasses import dataclass class A(BaseModel): a: str A('a') + +@dataclass +class B(): + a: str + + +B('a') diff --git a/testData/inspection/acceptsOnlyKeywordArgumentsSingleStarArgument.py b/testData/inspection/acceptsOnlyKeywordArgumentsSingleStarArgument.py index 9d363cea..eb4bd293 100644 --- a/testData/inspection/acceptsOnlyKeywordArgumentsSingleStarArgument.py +++ b/testData/inspection/acceptsOnlyKeywordArgumentsSingleStarArgument.py @@ -1,4 +1,5 @@ from pydantic import BaseModel +from pydantic.dataclasses import dataclass class A(BaseModel): @@ -6,3 +7,11 @@ class A(BaseModel): A(*['a']) + + +@dataclass +class B: + a: str + + +B(*['a'])