Skip to content

Commit

Permalink
Merge pull request #680 from koxudaxi/support_noqa
Browse files Browse the repository at this point in the history
Support # noqa
  • Loading branch information
koxudaxi authored Mar 20, 2023
2 parents b953a5b + bac0d1c commit fbc42f3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/com/koxudaxi/pydantic/PydanticAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.util.containers.nullize
import com.jetbrains.python.psi.PyCallExpression
import com.jetbrains.python.psi.PyStarArgument
import com.jetbrains.python.psi.types.PyCallableType

import com.jetbrains.python.psi.impl.PyPsiUtils
import com.jetbrains.python.psi.types.TypeEvalContext
import com.jetbrains.python.validation.PyAnnotator

Expand All @@ -17,6 +18,13 @@ class PydanticAnnotator : PyAnnotator() {
annotatePydanticModelCallableExpression(node)
}

private fun hasNoqaComment(
pyCallExpression: PyCallExpression
): Boolean {
val comment = PyPsiUtils.findSameLineComment(pyCallExpression) ?: return false
return comment.text.startsWith("# noqa")
}

private fun annotatePydanticModelCallableExpression(pyCallExpression: PyCallExpression) {
val context = TypeEvalContext.codeAnalysis(pyCallExpression.project, pyCallExpression.containingFile)
val pyClassType = pyCallExpression.getPyCallableType(context) ?: return
Expand All @@ -32,8 +40,12 @@ class PydanticAnnotator : PyAnnotator() {
.create()
unFilledArguments.filter { it.required }.nullize() ?: return
val highlight = when {
isSubClassOfBaseSetting(pyClass,
context) || pyCallExpression.arguments.any { (it as? PyStarArgument)?.isKeyword == true } -> HighlightSeverity.INFORMATION
isSubClassOfBaseSetting(
pyClass,
context
) || pyCallExpression.arguments.any { (it as? PyStarArgument)?.isKeyword == true } -> HighlightSeverity.INFORMATION

hasNoqaComment(pyCallExpression) -> HighlightSeverity.INFORMATION
else -> HighlightSeverity.WARNING
}
holder.newSilentAnnotation(highlight).withFix(PydanticInsertArgumentsQuickFix(true))
Expand Down

0 comments on commit fbc42f3

Please sign in to comment.