Skip to content

Commit

Permalink
fix fields module name for pydantic v1 (#71)
Browse files Browse the repository at this point in the history
* fix fields modules name for pydantic v1
  • Loading branch information
koxudaxi committed Sep 20, 2019
1 parent 5237b5a commit 12367bf
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 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">
<id>com.koxudaxi.pydantic</id>
<name>Pydantic</name>
<version>0.0.20</version>
<version>0.0.21</version>
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.0.21</h2>
<p>BugFixes</p>
<ul>
<li>Fix fields module name for pydantic v1 [#67] </li>
</ul>
<h2>version 0.0.20</h2>
<p>Features, BugFixes</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/Pydantic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const val BASE_MODEL_Q_NAME = "pydantic.main.BaseModel"
const val DATA_CLASS_Q_NAME = "pydantic.dataclasses.dataclass"
const val VALIDATOR_Q_NAME = "pydantic.validator"
const val SCHEMA_Q_NAME = "pydantic.schema.Schema"
const val FIELD_Q_NAME = "pydantic.field.Field"
const val FIELD_Q_NAME = "pydantic.fields.Field"
const val BASE_SETTINGS_Q_NAME = "pydantic.env_settings.BaseSettings"

internal fun getPyClassByPyCallExpression(pyCallExpression: PyCallExpression, context: TypeEvalContext): PyClass? {
Expand Down
22 changes: 22 additions & 0 deletions testData/completion/fieldField.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from builtins import *
from pydantic import BaseModel, Field

def get_alias():
return 'alias_c_id'
b_id = 'alias_b_id'
class A(BaseModel):
abc: str = Field(...)
cde = Field(str('abc'))
efg = Field(default=str('abc'))
hij = Field(default=...)
a_id: str = Field(..., alias='alias_a_id')
b_id: str = Field(..., alias=b_id)
c_id: str = Field(..., alias=get_alias())
d_id: str = Field(..., alias=)
e_id: str = Field(..., alias=broken)
f_id: str = Field(..., alias=123)
g_id: str = get_alias()
class B(A):
hij: str

A().<caret>
2 changes: 1 addition & 1 deletion testData/mock/pydantic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .main import BaseModel
from .class_validators import validator
from .schema import Schema
from .field import Field
from .fields import Field
from .env_settings import BaseSettings
File renamed without changes.
19 changes: 19 additions & 0 deletions testSrc/com/koxudaxi/pydantic/PydanticCompletionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,25 @@ open class PydanticCompletionTest : PydanticTestCase() {
)
}

fun testFieldField() {
doFieldTest(
listOf(
Pair("a_id","str A"),
Pair("abc", "str A"),
Pair("b_id","str A"),
Pair("c_id","str A"),
Pair("cde", "str=str('abc') A"),
Pair("d_id", "str A"),
Pair("e_id", "str A"),
Pair("efg", "str=str('abc') A"),
Pair("f_id", "str A"),
Pair("g_id", "str=get_alias() A"),
Pair("hij", "Any A"),
Pair("___slots__", "BaseModel")
)
)
}

fun testClassMethodCls() {
doFieldTest(
listOf(
Expand Down

0 comments on commit 12367bf

Please sign in to comment.