From ae58690bcef7fb4edef8c67e3dbbd241a35928a9 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Fri, 3 Dec 2021 00:27:51 +0900 Subject: [PATCH 1/2] Support PyCharm 2021.3 --- .github/workflows/CI.yml | 2 +- build.gradle | 6 +++--- resources/META-INF/plugin.xml | 7 ++++++- src/com/koxudaxi/pydantic/PydanticCacheService.kt | 2 +- src/com/koxudaxi/pydantic/PydanticConfigService.kt | 1 - src/com/koxudaxi/pydantic/PydanticInitializer.kt | 4 ++-- .../pydantic/PydanticInsertArgumentsQuickFix.kt | 2 +- src/com/koxudaxi/pydantic/PydanticInspection.kt | 7 ++++--- .../pydantic/PydanticPackageManagerListener.kt | 2 +- .../pydantic/PydanticTypeCheckerInspection.kt | 11 ++++++----- src/com/koxudaxi/pydantic/PydanticTypeProvider.kt | 2 +- .../pydantic/PydanticPackageManagerListenerTest.kt | 2 +- 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index bfd99676..e2c1603a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/build.gradle b/build.gradle index 41fed300..0c29f2d8 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { intellij { pluginName = project.name - version = "2021.2.2" + version = "2021.3" type = "PC" updateSinceUntilBuild = false downloadSources = true @@ -24,8 +24,8 @@ intellij { patchPluginXml { - sinceBuild = "212.5284.19" - untilBuild = "212.*" + sinceBuild = "213.5744.248" + untilBuild = "213.*" } diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 64fcc2ea..cca9309f 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,9 +1,14 @@ com.koxudaxi.pydantic Pydantic - 0.3.8 + 0.3.9 Koudai Aono @koxudaxi version 0.3.9 +

Features

+
    +
  • Support PyCharm 2021.3 [#400]
  • +

version 0.3.8

Features

    diff --git a/src/com/koxudaxi/pydantic/PydanticCacheService.kt b/src/com/koxudaxi/pydantic/PydanticCacheService.kt index 53145007..b409bae4 100644 --- a/src/com/koxudaxi/pydantic/PydanticCacheService.kt +++ b/src/com/koxudaxi/pydantic/PydanticCacheService.kt @@ -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) } } diff --git a/src/com/koxudaxi/pydantic/PydanticConfigService.kt b/src/com/koxudaxi/pydantic/PydanticConfigService.kt index 89dd35a3..35ad9d09 100644 --- a/src/com/koxudaxi/pydantic/PydanticConfigService.kt +++ b/src/com/koxudaxi/pydantic/PydanticConfigService.kt @@ -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 diff --git a/src/com/koxudaxi/pydantic/PydanticInitializer.kt b/src/com/koxudaxi/pydantic/PydanticInitializer.kt index 1111bd60..a5de61ba 100644 --- a/src/com/koxudaxi/pydantic/PydanticInitializer.kt +++ b/src/com/koxudaxi/pydantic/PydanticInitializer.kt @@ -82,7 +82,7 @@ class PydanticInitializer : StartupActivity { } } - } catch (e: AlreadyDisposedException) { + } catch (_: AlreadyDisposedException) { } } } @@ -179,7 +179,7 @@ class PydanticInitializer : StartupActivity { DumbService.getInstance(project).smartInvokeLater { try { initializeFileLoader(project) - } catch (e: AlreadyDisposedException) { + } catch (_: AlreadyDisposedException) { } } } diff --git a/src/com/koxudaxi/pydantic/PydanticInsertArgumentsQuickFix.kt b/src/com/koxudaxi/pydantic/PydanticInsertArgumentsQuickFix.kt index 55daa30f..7a65fa24 100644 --- a/src/com/koxudaxi/pydantic/PydanticInsertArgumentsQuickFix.kt +++ b/src/com/koxudaxi/pydantic/PydanticInsertArgumentsQuickFix.kt @@ -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, diff --git a/src/com/koxudaxi/pydantic/PydanticInspection.kt b/src/com/koxudaxi/pydantic/PydanticInspection.kt index 5f291e7e..93dca2c5 100644 --- a/src/com/koxudaxi/pydantic/PydanticInspection.kt +++ b/src/com/koxudaxi/pydantic/PydanticInspection.kt @@ -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() { @@ -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) diff --git a/src/com/koxudaxi/pydantic/PydanticPackageManagerListener.kt b/src/com/koxudaxi/pydantic/PydanticPackageManagerListener.kt index f26f354b..aca355ec 100644 --- a/src/com/koxudaxi/pydantic/PydanticPackageManagerListener.kt +++ b/src/com/koxudaxi/pydantic/PydanticPackageManagerListener.kt @@ -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) diff --git a/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt b/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt index 6422a008..fab6d2f9 100644 --- a/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt +++ b/src/com/koxudaxi/pydantic/PydanticTypeCheckerInspection.kt @@ -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 @@ -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) @@ -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() val cachedAcceptableTypeMap = mutableMapOf() @@ -162,7 +163,7 @@ class PydanticTypeCheckerInspection : PyTypeCheckerInspection() { private fun matchParameterAndArgument( parameterType: PyType?, argumentType: PyType?, - substitutions: Map, + substitutions: PyTypeChecker.GenericSubstitutions, ): Boolean { return PyTypeChecker.match(parameterType, argumentType, diff --git a/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt b/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt index aa0f20ce..53896f00 100644 --- a/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt +++ b/src/com/koxudaxi/pydantic/PydanticTypeProvider.kt @@ -565,7 +565,7 @@ class PydanticTypeProvider : PyTypeProviderBase() { ) } - internal fun argumentToParameter( + private fun argumentToParameter( parameter: PyNamedParameter, context: TypeEvalContext, typed: Boolean = true, diff --git a/testSrc/com/koxudaxi/pydantic/PydanticPackageManagerListenerTest.kt b/testSrc/com/koxudaxi/pydantic/PydanticPackageManagerListenerTest.kt index b1ff051b..ddde27a1 100644 --- a/testSrc/com/koxudaxi/pydantic/PydanticPackageManagerListenerTest.kt +++ b/testSrc/com/koxudaxi/pydantic/PydanticPackageManagerListenerTest.kt @@ -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) } From 21328020e945ab371f7207a066d605e2031a4622 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Fri, 3 Dec 2021 03:37:46 +0900 Subject: [PATCH 2/2] add dummy testmethod --- testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt b/testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt index e9bf36bc..011e5651 100644 --- a/testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt +++ b/testSrc/com/koxudaxi/pydantic/PydanticTestCase.kt @@ -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() { @@ -104,6 +105,8 @@ abstract class PydanticTestCase(version: String = "v1") : UsefulTestCase() { PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture!!.project, languageLevel) } - + @Test + private fun dummyTest() { + } }