Skip to content

Commit

Permalink
Support positional arguments for dataclasses (#91)
Browse files Browse the repository at this point in the history
* fix dataclass inspection
  • Loading branch information
koxudaxi committed Nov 27, 2019
1 parent 83cd142 commit 1e161dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.0.28</h2>
<p>BugFixes</p>
<p>Features, BugFixes</p>
<ul>
<li>Support positional arguments for dataclasses [#91] </li>
<li>Fix field names treated with incorrect scope [#90] </li>
</ul>
<h2>version 0.0.27</h2>
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/PydanticInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 8 additions & 1 deletion testData/inspection/acceptsOnlyKeywordArguments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from pydantic import BaseModel

from pydantic.dataclasses import dataclass

class A(BaseModel):
a: str


A(<warning descr="class 'A' accepts only keyword arguments">'a'</warning>)

@dataclass
class B():
a: str


B('a')
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from pydantic import BaseModel
from pydantic.dataclasses import dataclass


class A(BaseModel):
a: str


A(<warning descr="class 'A' accepts only keyword arguments">*['a']</warning>)


@dataclass
class B:
a: str


B(*['a'])

0 comments on commit 1e161dd

Please sign in to comment.