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 PyCharm 2021.3 #400

Merged
merged 2 commits into from
Dec 2, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: ChrisCarini/intellij-platform-plugin-verifier-action@v0.0.2
with:
ide-versions: |
pycharmPC:2021.1
pycharmPC:2021.3
pycharmPC:LATEST-EAP-SNAPSHOT
- name: setup python
uses: actions/setup-python@v1
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {

intellij {
pluginName = project.name
version = "2021.2.2"
version = "2021.3"
type = "PC"
updateSinceUntilBuild = false
downloadSources = true
Expand All @@ -24,8 +24,8 @@ intellij {


patchPluginXml {
sinceBuild = "212.5284.19"
untilBuild = "212.*"
sinceBuild = "213.5744.248"
untilBuild = "213.*"
}


Expand Down
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" require-restart="true">
<id>com.koxudaxi.pydantic</id>
<name>Pydantic</name>
<version>0.3.8</version>
<version>0.3.9</version>
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.3.9</h2>
<p>Features</p>
<ul>
<li>Support PyCharm 2021.3 [#400]</li>
</ul>
<h2>version 0.3.8</h2>
<p>Features</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/PydanticCacheService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PydanticCacheService {
}

private fun getInstance(project: Project): PydanticCacheService {
return ServiceManager.getService(project, PydanticCacheService::class.java)
return project.getService(PydanticCacheService::class.java)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/com/koxudaxi/pydantic/PydanticConfigService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.koxudaxi.pydantic

import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.project.Project
Expand Down
4 changes: 2 additions & 2 deletions src/com/koxudaxi/pydantic/PydanticInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PydanticInitializer : StartupActivity {
}
}

} catch (e: AlreadyDisposedException) {
} catch (_: AlreadyDisposedException) {
}
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class PydanticInitializer : StartupActivity {
DumbService.getInstance(project).smartInvokeLater {
try {
initializeFileLoader(project)
} catch (e: AlreadyDisposedException) {
} catch (_: AlreadyDisposedException) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PydanticInsertArgumentsQuickFix(private val onlyRequired: Boolean) : Local

override fun startInWriteAction(): Boolean = true

fun runFix(
private fun runFix(
project: Project,
file: PsiFile,
originalElement: PsiElement,
Expand Down
7 changes: 4 additions & 3 deletions src/com/koxudaxi/pydantic/PydanticInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.jetbrains.python.psi.impl.PyTargetExpressionImpl
import com.jetbrains.python.psi.resolve.PyResolveContext
import com.jetbrains.python.psi.types.PyClassType
import com.jetbrains.python.psi.types.PyClassTypeImpl
import com.jetbrains.python.psi.types.TypeEvalContext


class PydanticInspection : PyInspection() {
Expand All @@ -21,10 +22,10 @@ class PydanticInspection : PyInspection() {
holder: ProblemsHolder,
isOnTheFly: Boolean,
session: LocalInspectionToolSession,
): PsiElementVisitor = Visitor(holder, session)
): PsiElementVisitor = Visitor(holder, PyInspectionVisitor.getContext(session))

inner class Visitor(holder: ProblemsHolder, session: LocalInspectionToolSession) :
PyInspectionVisitor(holder, session) {
inner class Visitor(holder: ProblemsHolder, context: TypeEvalContext) :
PyInspectionVisitor(holder, context) {

val pydanticConfigService = PydanticConfigService.getInstance(holder.project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PydanticPackageManagerListener : PyPackageManager.Listener {
runWriteAction {
try {
pydanticStub.delete(this)
} catch (e: java.io.IOException) {
} catch (_: java.io.IOException) {
} finally {
pydanticStub.refresh(true, true) {
clearVersion(sdk)
Expand Down
11 changes: 6 additions & 5 deletions src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElementVisitor
import com.jetbrains.python.codeInsight.typing.matchingProtocolDefinitions
import com.jetbrains.python.documentation.PythonDocumentationProvider
import com.jetbrains.python.inspections.PyInspectionVisitor
import com.jetbrains.python.inspections.PyTypeCheckerInspection
import com.jetbrains.python.psi.PyCallExpression
import com.jetbrains.python.psi.PyCallExpression.PyArgumentsMapping
Expand All @@ -27,11 +28,11 @@ class PydanticTypeCheckerInspection : PyTypeCheckerInspection() {
if (LOG.isDebugEnabled) {
session.putUserData(TIME_KEY, System.nanoTime())
}
return Visitor(holder, session)
return Visitor(holder, PyInspectionVisitor.getContext(session))
}

class Visitor(holder: ProblemsHolder?, session: LocalInspectionToolSession) :
PyTypeCheckerInspection.Visitor(holder, session) {
class Visitor(holder: ProblemsHolder?, context: TypeEvalContext) :
PyTypeCheckerInspection.Visitor(holder, context) {

val pydanticConfigService = PydanticConfigService.getInstance(holder!!.project)

Expand Down Expand Up @@ -103,7 +104,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.unifyReceiver(receiver, myTypeEvalContext)
val substitutions = PyTypeChecker.unifyReceiverWithParamSpecs(receiver, myTypeEvalContext)
val mappedParameters = mapping.mappedParameters
val cachedParsableTypeMap = mutableMapOf<PyType, PyType?>()
val cachedAcceptableTypeMap = mutableMapOf<PyType, PyType?>()
Expand Down Expand Up @@ -162,7 +163,7 @@ class PydanticTypeCheckerInspection : PyTypeCheckerInspection() {
private fun matchParameterAndArgument(
parameterType: PyType?,
argumentType: PyType?,
substitutions: Map<PyGenericType, PyType>,
substitutions: PyTypeChecker.GenericSubstitutions,
): Boolean {
return PyTypeChecker.match(parameterType,
argumentType,
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() {
)
}

internal fun argumentToParameter(
private fun argumentToParameter(
parameter: PyNamedParameter,
context: TypeEvalContext,
typed: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ open class PydanticPackageManagerListenerTest : PydanticTestCase() {
invokeLater {
val privateVersionField = PydanticCacheService::class.java.getDeclaredField("version")
privateVersionField.trySetAccessible()
val pydanticVersionService = ServiceManager.getService(project, PydanticCacheService::class.java)
val pydanticVersionService = project.getService(PydanticCacheService::class.java)
val actual = privateVersionField.get(pydanticVersionService)
assertNull(actual)
}
Expand Down
5 changes: 4 additions & 1 deletion testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.jetbrains.python.fixtures.PyLightProjectDescriptor
import com.jetbrains.python.psi.LanguageLevel
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher
import com.jetbrains.python.sdk.PythonSdkUtil
import org.junit.Test

abstract class PydanticTestCase(version: String = "v1") : UsefulTestCase() {

Expand Down Expand Up @@ -104,6 +105,8 @@ abstract class PydanticTestCase(version: String = "v1") : UsefulTestCase() {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture!!.project, languageLevel)
}


@Test
private fun dummyTest() {
}
}