Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support BaseSettings #38

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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">
<id>com.koxudaxi.pydantic</id>
<name>Pydantic</name>
<version>0.0.12</version>
<version>0.0.13</version>
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.0.13</h2>
<p>Features</p>
<ul>
<li>No arguments required for BaseSettings [#] </li>
</ul>
<h2>version 0.0.12</h2>
<p>Features</p>
<ul>
Expand Down
11 changes: 8 additions & 3 deletions src/com/koxudaxi/pydantic/PydanticTypeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PydanticTypeProvider : PyTypeProviderBase() {
.asReversed()
.asSequence()
.filterNot { PyTypingTypeProvider.isClassVar(it, context) }
.mapNotNull { fieldToParameter(it, ellipsis, context) }
.mapNotNull { fieldToParameter(it, ellipsis, context, current) }
.forEach { parameter ->
parameter.name?.let {
if (!collected.containsKey(it)) {
Expand All @@ -105,16 +105,21 @@ class PydanticTypeProvider : PyTypeProviderBase() {

private fun fieldToParameter(field: PyTargetExpression,
ellipsis: PyNoneLiteralExpression,
context: TypeEvalContext): PyCallableParameter? {
context: TypeEvalContext,
pyClass: PyClass): PyCallableParameter? {
val stub = field.stub
val fieldStub = if (stub == null) PydanticFieldStubImpl.create(field) else stub.getCustomStub(PydanticFieldStub::class.java)
if (fieldStub != null && !fieldStub.initValue()) return null
if (fieldStub == null && field.annotationValue == null) return null // skip fields that are not annotated

val defaultValue = when {
pyClass.isSubclass("pydantic.env_settings.BaseSettings", context) -> ellipsis
else -> getDefaultValueForParameter(field, fieldStub, ellipsis, context)
}

return PyCallableParameterImpl.nonPsi(field.name,
getTypeForParameter(field, context),
getDefaultValueForParameter(field, fieldStub, ellipsis, context))
defaultValue)
}

private fun getTypeForParameter(field: PyTargetExpression,
Expand Down