Skip to content

Commit

Permalink
Support PyCharm 2023.3 (#840)
Browse files Browse the repository at this point in the history
* Support PyCharm 2023.3

* Update CHANGELOG.md

* Update version

* Update version

* Update version

* define the version
  • Loading branch information
koxudaxi committed Dec 7, 2023
1 parent f080188 commit 673674b
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Support PyCharm 2023.3 [[#840](https://github.com/koxudaxi/pydantic-pycharm-plugin/pull/840)]

## [0.4.9] - 2023-10-12

Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ tasks {
})
}

runPluginVerifier {
ideVersions.set(listOf("PC-2023.3"))
}

// Configure UI tests plugin
// Read more: https://github.com/JetBrains/intellij-ui-test-robot
runIdeForUiTests {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pluginGroup = com.koxudaxi.pydantic
pluginName = Pydantic
pluginRepositoryUrl = https://github.com/koxudaxi/pydantic-pycharm-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.4.9
pluginVersion = 0.4.10

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
pluginSinceBuild = 233.11799.241
pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = PC
platformVersion = 233.9102.128-EAP-SNAPSHOT
platformVersion = 2023.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PydanticTypeCheckerInspection : PyTypeCheckerInspection() {
private fun analyzeCallee(callSite: PyCallSiteExpression, mapping: PyArgumentsMapping) {
val callableType = mapping.callableType ?: return
val receiver = callSite.getReceiver(callableType.callable)
val substitutions = PyTypeChecker.unifyReceiverWithParamSpecs(receiver, myTypeEvalContext)
val substitutions = PyTypeChecker.unifyReceiver(receiver, myTypeEvalContext)
val mappedParameters = mapping.mappedParameters
val cachedParsableTypeMap = mutableMapOf<PyType, PyType?>()
val cachedAcceptableTypeMap = mutableMapOf<PyType, PyType?>()
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/PydanticTypeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class PydanticTypeProvider : PyTypeProviderBase() {
}?.let {
when (genericTypeMap) {
null -> it
else -> PyTypeChecker.substitute(it, genericTypeMap, context)
else -> PyTypeChecker.substitute(it, PyTypeChecker.GenericSubstitutions(genericTypeMap), context)
}
}

Expand Down
8 changes: 4 additions & 4 deletions testData/typeinspection/dynamicModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StaticFoobarModel(BaseModel):


DynamicFoobarModel(foo='name', bar=123)
DynamicFoobarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>)
DynamicFoobarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>)

BarModel = create_model(
model_name='BarModel',
Expand All @@ -18,7 +18,7 @@ class StaticFoobarModel(BaseModel):
)

BarModel(foo='name', bar=123, apple='green', banana='red')
BarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
BarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)

model_name = 'DynamicBarModel'
DynamicBarModel = create_model(
Expand All @@ -29,12 +29,12 @@ class StaticFoobarModel(BaseModel):
)

DynamicBarModel(foo='name', bar=123, apple='green', banana='red')
DynamicBarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
DynamicBarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)

DynamicModifiedBarModel = create_model('DynamicModifiedFoobarModel', foo=(int, ...), bar='abc', __base__=DynamicBarModel)

DynamicModifiedBarModel(foo=456, bar='efg', apple='green', banana='red')
DynamicModifiedBarModel(<warning descr="Expected type 'int', got 'LiteralString' instead">foo='123'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">bar=456</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
DynamicModifiedBarModel(<warning descr="Expected type 'int', got 'str' instead">foo='123'</warning>, <warning descr="Expected type 'str', got 'int' instead">bar=456</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)


DynamicBrokenModel = create_model(
Expand Down
4 changes: 2 additions & 2 deletions testData/typeinspectionv18/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class ChildDataclass(MyDataclass):
d: int

MyDataclass(a='apple', b=1)
MyDataclass(<warning descr="Expected type 'str', got 'int' instead">a=2</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">b='orange'</warning>)
MyDataclass(<warning descr="Expected type 'str', got 'int' instead">a=2</warning>, <warning descr="Expected type 'int', got 'str' instead">b='orange'</warning>)

ChildDataclass(a='apple', b=1, c='berry', d=3)
ChildDataclass(<warning descr="Expected type 'str', got 'int' instead">a=2</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">b='orange'</warning>, <warning descr="Expected type 'str', got 'int' instead">c=4</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">d='cherry'</warning>)
ChildDataclass(<warning descr="Expected type 'str', got 'int' instead">a=2</warning>, <warning descr="Expected type 'int', got 'str' instead">b='orange'</warning>, <warning descr="Expected type 'str', got 'int' instead">c=4</warning>, <warning descr="Expected type 'int', got 'str' instead">d='cherry'</warning>)


a: MyDataclass = MyDataclass(<warning descr="null">)</warning>
Expand Down
8 changes: 4 additions & 4 deletions testData/typeinspectionv18/dynamicModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StaticFoobarModel(BaseModel):


DynamicFoobarModel(foo='name', bar=123)
DynamicFoobarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>)
DynamicFoobarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>)

BarModel = create_model(
__model_name='BarModel',
Expand All @@ -18,7 +18,7 @@ class StaticFoobarModel(BaseModel):
)

BarModel(foo='name', bar=123, apple='green', banana='red')
BarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
BarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)

model_name = 'DynamicBarModel'
DynamicBarModel = create_model(
Expand All @@ -29,9 +29,9 @@ class StaticFoobarModel(BaseModel):
)

DynamicBarModel(foo='name', bar=123, apple='green', banana='red')
DynamicBarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'LiteralString' instead">bar='name'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
DynamicBarModel(<warning descr="Expected type 'str', got 'int' instead">foo=123</warning>, <warning descr="Expected type 'int', got 'str' instead">bar='name'</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)

DynamicModifiedBarModel = create_model('DynamicModifiedFoobarModel', foo=(int, ...), bar='abc', __base__=DynamicBarModel)

DynamicModifiedBarModel(foo=456, bar='efg', apple='green', banana='red')
DynamicModifiedBarModel(<warning descr="Expected type 'int', got 'LiteralString' instead">foo='123'</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">bar=456</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">banana=456</warning>)
DynamicModifiedBarModel(<warning descr="Expected type 'int', got 'str' instead">foo='123'</warning>, <warning descr="Expected type 'str', got 'int' instead">bar=456</warning>, <warning descr="Expected type 'str', got 'int' instead">apple=123</warning>, <warning descr="Expected type 'str', got 'int' instead">banana=456</warning>)
18 changes: 9 additions & 9 deletions testData/typeinspectionv18/genericModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ChildClass(BaseClass[int, TypeY], Generic[TypeY, TypeZ]):
# Replace TypeY by str
ChildClass[str, float](x=1, y='y', z=3.1)

ChildClass[float, bytes](<warning descr="Expected type 'int', got 'bytes' instead">x=b'1'</warning>, <warning descr="Expected type 'float', got 'LiteralString' instead">y='y'</warning>, <warning descr="Expected type 'bytes', got 'int' instead">z=1_3</warning>)
ChildClass[float, bytes](<warning descr="Expected type 'int', got 'bytes' instead">x=b'1'</warning>, <warning descr="Expected type 'float', got 'str' instead">y='y'</warning>, <warning descr="Expected type 'bytes', got 'int' instead">z=1_3</warning>)

DataT = TypeVar('DataT')

Expand All @@ -78,7 +78,7 @@ def __concrete_name__(cls: Type[Any], params: Tuple[Type[Any], ...]) -> str:


Response[str](<warning descr="Expected type 'str', got 'int' instead">data=1</warning>)
Response[float](<warning descr="Expected type 'float', got 'LiteralString' instead">data='a'</warning>)
Response[float](<warning descr="Expected type 'float', got 'str' instead">data='a'</warning>)


T = TypeVar('T')
Expand All @@ -97,7 +97,7 @@ class OuterT(GenericModel, Generic[T]):
OuterT[int](outer=1, nested=nested)

nested = InnerT[str](inner='a')
OuterT[int](<warning descr="Expected type 'int', got 'LiteralString' instead">outer='a'</warning>, <warning descr="Expected type 'InnerT[int]', got 'InnerT[str]' instead">nested=nested</warning>)
OuterT[int](<warning descr="Expected type 'int', got 'str' instead">outer='a'</warning>, <warning descr="Expected type 'InnerT[int]', got 'InnerT[str]' instead">nested=nested</warning>)

AT = TypeVar('AT')
BT = TypeVar('BT')
Expand All @@ -116,7 +116,7 @@ class Model(GenericModel, Generic[AT, BT]):
typevar_model(a=1, b=1)


typevar_model(<warning descr="Expected type 'int', got 'LiteralString' instead">a='a'</warning>, <warning descr="Expected type 'IntT', got 'LiteralString' instead">b='a'</warning>)
typevar_model(<warning descr="Expected type 'int', got 'str' instead">a='a'</warning>, <warning descr="Expected type 'IntT', got 'str' instead">b='a'</warning>)

concrete_model = typevar_model[int]
concrete_model(a=1, b=1)
Expand All @@ -142,7 +142,7 @@ class Model(GenericModel, Generic[CT, DT]):

Model[int, int](a=[int], b=[2])

Model[int, int](<warning descr="Expected type 'List[Type[int]]', got 'int' instead">a=1</warning>, <warning descr="Expected type 'Union[List[int], float]', got 'LiteralString' instead">b='2'</warning>)
Model[int, int](<warning descr="Expected type 'List[Type[int]]', got 'int' instead">a=1</warning>, <warning descr="Expected type 'Union[List[int], float]', got 'str' instead">b='2'</warning>)

class Model(GenericModel, Generic[CT, DT, ET, FT]):
a: CT
Expand All @@ -167,7 +167,7 @@ class Model(GenericModel, Generic[CT]):

Model[Union[int, float]](a=1)

Model[Union[int, float]](<warning descr="Expected type 'Union[int, float]', got 'LiteralString' instead">a='1'</warning>)
Model[Union[int, float]](<warning descr="Expected type 'Union[int, float]', got 'str' instead">a='1'</warning>)

class Model(GenericModel, Generic[CT, DT]):
a: CT
Expand All @@ -178,7 +178,7 @@ def x(b: ET) -> ET:

Model[x(int), Optional[x(int)]](a=1, b=2)

Model[x(int), Optional[x(int)]](<warning descr="Expected type 'int', got 'LiteralString' instead">a='1'</warning>, <warning descr="Expected type 'Optional[int]', got 'LiteralString' instead">b='2'</warning>)
Model[x(int), Optional[x(int)]](<warning descr="Expected type 'int', got 'str' instead">a='1'</warning>, <warning descr="Expected type 'Optional[int]', got 'str' instead">b='2'</warning>)

class Model(GenericModel, Generic[CT, DT]):
a: CT
Expand All @@ -188,12 +188,12 @@ class Model(GenericModel, Generic[CT, DT]):

Model[y, Optional[y]](a=1, b=2)

Model[y, Optional[y]](<warning descr="Expected type 'int', got 'LiteralString' instead">a='1'</warning>, <warning descr="Expected type 'Optional[int]', got 'LiteralString' instead">b='2'</warning>)
Model[y, Optional[y]](<warning descr="Expected type 'int', got 'str' instead">a='1'</warning>, <warning descr="Expected type 'Optional[int]', got 'str' instead">b='2'</warning>)


class Model(GenericModel, Generic[CT, DT, ET, FT, aaaaaaaaaa]):
a: Type[CT]
b: List[aaaaa]
c: Dict[ET, aaaaaaaa]

Model[aaaaaaaaaa, List[aaaaaa], Tuple[aaaaaaaaaa], Type[aaaaaaaaaaa]](a=int, b=[2], <warning descr="Expected type 'Dict[Tuple[Any], Any]', got 'Dict[LiteralString, int]' instead">c={'c': 3}</warning>)
Model[aaaaaaaaaa, List[aaaaaa], Tuple[aaaaaaaaaa], Type[aaaaaaaaaaa]](a=int, b=[2], <warning descr="Expected type 'Dict[Tuple[Any], Any]', got 'Dict[str, int]' instead">c={'c': 3}</warning>)
2 changes: 1 addition & 1 deletion testData/typeinspectionv18/sqlModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class Hero(SQLModel, table=True):

hero_4 = Hero(secret_name="test"<warning descr="null">)</warning>

hero_5 = Hero(<warning descr="Expected type 'str', got 'int' instead">name=123</warning>, <warning descr="Expected type 'LiteralString', got 'int' instead">secret_name=456</warning>, <warning descr="Expected type 'Optional[int]', got 'LiteralString' instead">age="abc"</warning>)
hero_5 = Hero(<warning descr="Expected type 'str', got 'int' instead">name=123</warning>, <warning descr="Expected type 'str', got 'int' instead">secret_name=456</warning>, <warning descr="Expected type 'Optional[int]', got 'str' instead">age="abc"</warning>)
1 change: 1 addition & 0 deletions testSrc/com/koxudaxi/pydantic/PydanticCompletionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open class PydanticCompletionTest : PydanticTestCase() {
"__slots__",
"__text_signature__",
"__weakrefoffset__",
"__type_params__",
"Ellipsis",
"EnvironmentError",
"IOError",
Expand Down

0 comments on commit 673674b

Please sign in to comment.