Skip to content

Commit

Permalink
Merge pull request #46 from koxudaxi/support_default_values
Browse files Browse the repository at this point in the history
Support default values
  • Loading branch information
koxudaxi committed Aug 19, 2019
2 parents 61b9876 + d2a1c7a commit 57e96c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<h2>version 0.0.14</h2>
<p>Features</p>
<ul>
<li>Ignore warning for `self` argument with @validator
<li>Support default values [#46] <li>
<li>Ignore warning for self argument with @validator [#45] </li>
<li>Support pydantic.dataclasses.dataclass [#43] </li>
<li>Search related-fields by class attributes and keyword arguments of __init__. with Ctrl+B and Cmd+B [#42] </li>
</ul>
Expand Down Expand Up @@ -41,7 +42,7 @@
</li>
<li>pydantic.dataclasses.dataclass
<ul>
<li>Support same features as `pydantic.BaseModel`</li>
<li>Support same features as pydantic.BaseModel</li>
</ul>
</li>
</ul>
Expand Down
14 changes: 7 additions & 7 deletions src/com/koxudaxi/pydantic/PydanticTypeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class PydanticTypeProvider : PyTypeProviderBase() {
if (assignedValue.text == "...") {
return null
}
val callee = (assignedValue as? PyCallExpressionImpl)?.callee ?: return ellipsis

val callee = (assignedValue as? PyCallExpressionImpl)?.callee ?: return assignedValue
val referenceExpression = callee.reference?.element as? PyReferenceExpression ?: return ellipsis

val resolveResults = getResolveElements(referenceExpression, context)
Expand All @@ -180,14 +181,13 @@ class PydanticTypeProvider : PyTypeProviderBase() {
if (pyClass != null && isPydanticField(pyClass, context)) {
val defaultValue = assignedValue.getKeywordArgument("default")
?: assignedValue.getArgument(0, PyExpression::class.java)
when {
defaultValue == null -> return null
defaultValue.text == "..." -> return null
defaultValue.text == null -> return ellipsis
defaultValue.text.isNotBlank() -> return ellipsis
return when {
defaultValue == null -> null
defaultValue.text == "..." -> null
else -> defaultValue
}
}
}
return ellipsis
return assignedValue
}
}

0 comments on commit 57e96c2

Please sign in to comment.