Skip to content

Commit

Permalink
Merge pull request #306 from koxudaxi/fix_wrong_call_parameter_with_k…
Browse files Browse the repository at this point in the history
…wargs

Fix wrong call parameter with **kwargs
  • Loading branch information
koxudaxi authored May 23, 2021
2 parents 68132eb + c50ee2e commit 94ce8ea
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<idea-plugin url="https://github.com/koxudaxi/pydantic-pycharm-plugin" require-restart="true">
<id>com.koxudaxi.pydantic</id>
<name>Pydantic</name>
<version>0.3.2</version>
<version>0.3.3</version>
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.3.3</h2>
<p>BugFixes</p>
<ul>
<li>Fix wrong call parameter with **kwargs [#306]</li>
</ul>
<h2>version 0.3.2</h2>
<p>BugFixes</p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions src/com/koxudaxi/pydantic/PydanticAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PydanticAnnotator : PyAnnotator() {
private fun annotatePydanticModelCallableExpression(pyCallExpression: PyCallExpression) {
val context = TypeEvalContext.userInitiated(pyCallExpression.project, pyCallExpression.containingFile)
val pyClass = getPydanticPyClass(pyCallExpression, context) ?: return
if (getPydanticModelInit(pyClass, context) != null) return
val unFilledArguments =
getPydanticUnFilledArguments(pyClass, pyCallExpression, pydanticTypeProvider, context).nullize()
?: return
Expand Down
1 change: 1 addition & 0 deletions src/com/koxudaxi/pydantic/PydanticInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PydanticInspection : PyInspection() {

private fun inspectPydanticModelCallableExpression(pyCallExpression: PyCallExpression) {
val pyClass = getPydanticPyClass(pyCallExpression, myTypeEvalContext) ?: return
if (getPydanticModelInit(pyClass, myTypeEvalContext) != null) return
pyCallExpression.arguments
.filterNot { it is PyKeywordArgument || (it as? PyStarArgument)?.isKeyword == true }
.forEach {
Expand Down
3 changes: 1 addition & 2 deletions src/com/koxudaxi/pydantic/PydanticTypeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ class PydanticTypeProvider : PyTypeProviderBase() {
val clsType = (context.getType(pyClass) as? PyClassLikeType) ?: return null

getPydanticModelInit(pyClass, context)?.let {
val callParameters = it.parameterList.parameters
val callParameters = it.getParameters(context)
.filterNot { parameter -> parameter.isSelf }
.map { parameter -> PyCallableParameterImpl.psi(parameter) }
return PyCallableTypeImpl(callParameters, clsType.toInstance())
}

Expand Down
17 changes: 17 additions & 0 deletions testData/inspection/acceptsOnlyKeywordArgumentsInit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pydantic import BaseModel
from pydantic.dataclasses import dataclass

class A(BaseModel):
a: str

def __init__(self, a = '123') -> None:
super(A, self).__init__(a=a)

A('a')

@dataclass
class B():
a: str


B('a')
4 changes: 4 additions & 0 deletions testSrc/com/koxudaxi/pydantic/PydanticInspectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ open class PydanticInspectionTest : PydanticInspectionBase() {
doTest()
}

fun testAcceptsOnlyKeywordArgumentsInit() {
doTest()
}

fun testAcceptsOnlyKeywordArgumentsSingleStarArgument() {
doTest()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ open class PydanticTypeInspectionV18Test : PydanticInspectionBase("v18") {
fun testGenericModel() {
doTest()
}

fun testOverrideInit() {
doTest()
}
}

0 comments on commit 94ce8ea

Please sign in to comment.