PY-71002 PEP-696: Suppress pep8 inspection for type parameters for

It cannot handle whitespaces around `=` in new-style type parameter declarations correctly

GitOrigin-RevId: c1d09acd54a329fbe4ff9d4ac8bd95a928440caf
This commit is contained in:
Daniil Kalinin
2024-09-07 11:11:13 +00:00
committed by intellij-monorepo-bot
parent 82fca2f070
commit ccefd0e23f
2 changed files with 27 additions and 0 deletions
@@ -839,6 +839,7 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<customPackageIdentifier implementation="com.jetbrains.python.namespacePackages.PyNamespacePackageCustomIdentifier"/>
<pyRootTypeProvider implementation="com.jetbrains.python.namespacePackages.PyNamespacePackageRootProvider"/>
<pep8ProblemSuppressor implementation="com.jetbrains.python.validation.Pep8TypeParameterProblemSuppressor"/>
<!-- Experimental packaging extensions-->
<pySdkProvider implementation="com.jetbrains.python.sdk.pipenv.PyPipEnvSdkProvider"/>
@@ -0,0 +1,26 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.validation;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.jetbrains.python.psi.PyTypeParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Pep8TypeParameterProblemSuppressor implements Pep8ProblemSuppressor {
public static final String UNEXPECTED_SPACES_AROUND_KEYWORD = "E251";
public static final String MISSING_WHITESPACE_AROUND_OPERATOR = "E225";
@Override
public boolean isProblemSuppressed(Pep8ExternalAnnotator.@NotNull Problem problem,
@NotNull PsiFile file,
@Nullable PsiElement targetElement) {
if (targetElement != null) {
return ((problem.getCode().equals(UNEXPECTED_SPACES_AROUND_KEYWORD)
|| problem.getCode().equals(MISSING_WHITESPACE_AROUND_OPERATOR))
&& targetElement.getParent() instanceof PyTypeParameter);
}
return false;
}
}