i18n: Extract messages and annotate several trivial Python inspections

GitOrigin-RevId: d7ed1efc53ae0c8034e8aa52def685b421c9b4cb
This commit is contained in:
Mikhail Golubev
2020-08-19 14:22:05 +00:00
committed by intellij-monorepo-bot
parent 660127e54e
commit 7d9e25a990
10 changed files with 40 additions and 20 deletions
@@ -126,7 +126,7 @@
<localInspection language="Python" shortName="PyBroadExceptionInspection" suppressId="PyBroadException" bundle="messages.PyPsiBundle" key="INSP.NAME.too.broad.exception.clauses" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyBroadExceptionInspection"/>
<localInspection language="Python" shortName="PyByteLiteralInspection" suppressId="PyByteLiteral" bundle="messages.PyPsiBundle" key="INSP.NAME.byte.literal" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyByteLiteralInspection"/>
<localInspection language="Python" shortName="PyCallByClassInspection" suppressId="PyCallByClass" bundle="messages.PyPsiBundle" key="INSP.NAME.different.class.call" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyCallByClassInspection"/>
<localInspection language="Python" shortName="PyCallingNonCallableInspection" suppressId="PyCallingNonCallable" bundle="messages.PyPsiBundle" key="INSP.calling.non.callable" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyCallingNonCallableInspection"/>
<localInspection language="Python" shortName="PyCallingNonCallableInspection" suppressId="PyCallingNonCallable" bundle="messages.PyPsiBundle" key="INSP.NAME.calling.non.callable" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyCallingNonCallableInspection"/>
<localInspection language="Python" shortName="PyComparisonWithNoneInspection" suppressId="PyComparisonWithNone" bundle="messages.PyPsiBundle" key="INSP.NAME.comparison.with.none" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyComparisonWithNoneInspection"/>
<localInspection language="Python" shortName="PyDataclassInspection" suppressId="PyDataclass" bundle="messages.PyPsiBundle" key="INSP.dataclass.definition.and.usages" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDataclassInspection"/>
<localInspection language="Python" shortName="PyDictCreationInspection" suppressId="PyDictCreation" bundle="messages.PyPsiBundle" key="INSP.NAME.dict.creation" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyDictCreationInspection"/>
@@ -415,6 +415,9 @@ QFIX.add.method.to.class=Add method to class
QFIX.install.and.import.package=Install and import package
QFIX.NAME.install.and.import.package=Install and import package ''{0}''
# PyAsyncCallInspection
QFIX.coroutine.is.not.awaited=Coroutine is not awaited
# Actions and associated commands
ACT.CMD.use.import=Use an imported module
@@ -439,7 +442,6 @@ INSP.pep8.naming=PEP 8 naming convention violation
INSP.pep8.naming.excluded.base.classes=Excluded base classes
INSP.pep8.naming.ignored.errors=Ignored errors
INSP.shadowing.builtins=Shadowing built-ins
INSP.calling.non.callable=Trying to call a non-callable object
INSP.dataclass.definition.and.usages=Dataclass definition and usages
INSP.dunder.slots=Definition of __slots__ in a class
INSP.final.classes.methods.and.variables=Final classes, methods and variables
@@ -500,6 +502,12 @@ INSP.type.checker=Type checker
INSP.type.hints=Type hints definitions and usages
INSP.typed.dict=TypedDict definition and usages
# PyCallingNonCallableInspection
INSP.NAME.calling.non.callable=Trying to call a non-callable object
INSP.class.object.is.not.callable=''{0}'' object is not callable
INSP.symbol.is.not.callable=''{0}'' is not callable
INSP.expression.is.not.callable=Expression is not callable
# PyArgumentListInspection
INSP.NAME.incorrect.call.arguments=Incorrect call arguments
INSP.cannot.appear.past.keyword.arg=Cannot appear past keyword arguments or *arg or **kwarg
@@ -703,18 +711,24 @@ INSP.unused.locals.ignore.variables.used.in.tuple.unpacking=Ignore variables use
# PyChainedComparsonsInspection
INSP.NAME.chained.comparisons=Chained comparisons can be simplified
INSP.chained.comparisons.ignore.statements.with.constant.in.the.middle=Ignore statements with a constant in the middle
INSP.simplify.chained.comparison=Simplify chained comparison
# PyAugmentAssignmentInspection
INSP.NAME.augment.assignment=Assignment can be replaced with augmented assignment
INSP.assignment.can.be.replaced.with.augmented.assignment=Assignment can be replaced with augmented assignment
# PyBroadExceptionInspection
INSP.NAME.too.broad.exception.clauses=Too broad exception clauses
INSP.too.broad.exception.clause=Too broad exception clause
# PyByteLiteralInspection
INSP.NAME.byte.literal=Byte literal contains characters > 255
INSP.byte.literal.contains.illegal.characters=Byte literal contains characters > 255
# PyComparisonWithNoneInspection
INSP.NAME.comparison.with.none=Comparison with None performed with equality operators
INSP.comparison.with.none.performed.with.equality.operators=Comparison with None performed with equality operators
# PyDictCreationInspection
INSP.NAME.dict.creation=Dictionary creation could be rewritten by dictionary literal
@@ -76,8 +76,6 @@ class PyAsyncCallInspection : PyInspection() {
"asyncio.tasks.ensure_future",
"asyncio.ensure_future")
const val coroutineIsNotAwaited = "Coroutine is not awaited"
private fun getCalledCoroutineName(callExpression: PyCallExpression, resolveContext: PyResolveContext): String? {
val callee = callExpression.callee as? PyReferenceExpression ?: return null
val function = callExpression.multiResolveCalleeFunction(resolveContext).firstOrNull() as? PyFunction ?: return null
@@ -95,7 +93,7 @@ class PyAsyncCallInspection : PyInspection() {
}
private class PyAddAwaitCallForCoroutineFix(val type: AwaitableType) : LocalQuickFix {
override fun getFamilyName() = coroutineIsNotAwaited
override fun getFamilyName() = PyPsiBundle.message("QFIX.coroutine.is.not.awaited")
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val psiElement = descriptor.psiElement
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.inspections.quickfix.AugmentedAssignmentQuickFix;
import com.jetbrains.python.psi.*;
@@ -104,7 +105,7 @@ public class PyAugmentAssignmentInspection extends PyInspection {
final PyElementType operator = value.getOperator();
if (operator != null && assignmentCanBeReplaced(mainOperandExpression, otherOperandExpression, operator, changedParts)) {
registerProblem(node, "Assignment can be replaced with augmented assignment", new AugmentedAssignmentQuickFix());
registerProblem(node, PyPsiBundle.message("INSP.assignment.can.be.replaced.with.augmented.assignment"), new AugmentedAssignmentQuickFix());
}
}
}
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiReference;
import com.intellij.util.containers.Stack;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.types.PyClassType;
import com.jetbrains.python.psi.types.PyType;
@@ -60,7 +61,7 @@ public class PyBroadExceptionInspection extends PyInspection {
if (reRaised(node))
return;
if (exceptClass == null) {
registerProblem(node.getFirstChild(), "Too broad exception clause");
registerProblem(node.getFirstChild(), PyPsiBundle.message("INSP.too.broad.exception.clause"));
}
if (exceptClass != null) {
final PyType type = myTypeEvalContext.getType(exceptClass);
@@ -68,7 +69,7 @@ public class PyBroadExceptionInspection extends PyInspection {
final PyClass cls = ((PyClassType)type).getPyClass();
final PyExpression target = node.getTarget();
if (equalsException(cls, myTypeEvalContext) && (target == null || !isExceptionUsed(node, target.getText()))) {
registerProblem(exceptClass, "Too broad exception clause");
registerProblem(exceptClass, PyPsiBundle.message("INSP.too.broad.exception.clause"));
}
}
}
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyStringLiteralExpression;
@@ -85,7 +86,7 @@ public class PyByteLiteralInspection extends PyInspection {
boolean isByte = first_char == 'b' || (default_bytes && first_char != 'u');
if (hasNonAscii && isByte) {
registerProblem(node, "Byte literal contains characters > 255");
registerProblem(node, PyPsiBundle.message("INSP.byte.literal.contains.illegal.characters"));
}
}
}
@@ -17,8 +17,10 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.util.InspectionMessage;
import com.intellij.psi.PsiElementVisitor;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.PyRemoveCallQuickFix;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.types.PyClassType;
@@ -67,14 +69,14 @@ public class PyCallingNonCallableInspection extends PyInspection {
if (callee != null && isCallable(callee, myTypeEvalContext) == Boolean.FALSE) {
final PyType calleeType = myTypeEvalContext.getType(callee);
String message = "Expression is not callable";
@InspectionMessage String message = PyPsiBundle.message("INSP.expression.is.not.callable");
if (calleeType instanceof PyClassType) {
message = String.format("'%s' object is not callable", calleeType.getName());
message = PyPsiBundle.message("INSP.class.object.is.not.callable", calleeType.getName());
}
else {
final String name = callee.getName();
if (name != null) {
message = String.format("'%s' is not callable", name);
message = PyPsiBundle.message("INSP.symbol.is.not.callable", name);
}
}
registerProblem(node, message, new PyRemoveCallQuickFix());
@@ -23,6 +23,7 @@ import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonUiService;
import com.jetbrains.python.inspections.quickfix.ChainedComparisonsQuickFix;
@@ -47,14 +48,14 @@ import static com.jetbrains.python.psi.PyUtil.as;
*/
public class PyChainedComparisonsInspection extends PyInspection {
protected static final String ourIgnoreConstantOptionText = "Ignore statements with a constant in the middle";
private static final String INSPECTION_SHORT_NAME = "PyChainedComparisonsInspection";
public boolean ignoreConstantInTheMiddle = false;
@Nullable
@Override
public JComponent createOptionsPanel() {
JCheckBox checkBox = PythonUiService.getInstance().createInspectionCheckBox(ourIgnoreConstantOptionText, this, "ignoreConstantInTheMiddle");
JCheckBox checkBox = PythonUiService.getInstance().createInspectionCheckBox(
PyPsiBundle.message("INSP.chained.comparisons.ignore.statements.with.constant.in.the.middle"), this, "ignoreConstantInTheMiddle");
final JPanel rootPanel = new JPanel(new BorderLayout());
if (checkBox != null) {
rootPanel.add(checkBox,
@@ -118,12 +119,12 @@ public class PyChainedComparisonsInspection extends PyInspection {
if (applicable) {
if (isConstantInTheMiddle) {
if (!ignoreConstantInTheMiddle) {
registerProblem(node, "Simplify chained comparison", new ChainedComparisonsQuickFix(myIsLeft, myIsRight, getInnerRight),
registerProblem(node, PyPsiBundle.message("INSP.simplify.chained.comparison"), new ChainedComparisonsQuickFix(myIsLeft, myIsRight, getInnerRight),
new DontSimplifyStatementsWithConstantInTheMiddleQuickFix());
}
}
else {
registerProblem(node, "Simplify chained comparison", new ChainedComparisonsQuickFix(myIsLeft, myIsRight, getInnerRight));
registerProblem(node, PyPsiBundle.message("INSP.simplify.chained.comparison"), new ChainedComparisonsQuickFix(myIsLeft, myIsRight, getInnerRight));
}
}
}
@@ -240,7 +241,7 @@ public class PyChainedComparisonsInspection extends PyInspection {
@NotNull
@Override
public String getFamilyName() {
return ourIgnoreConstantOptionText;
return PyPsiBundle.message("INSP.chained.comparisons.ignore.statements.with.constant.in.the.middle");
}
@Override
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiReference;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.inspections.quickfix.ComparisonWithNoneQuickFix;
import com.jetbrains.python.psi.*;
@@ -57,7 +58,7 @@ public class PyComparisonWithNoneInspection extends PyInspection {
assert reference != null;
PsiElement result = reference.resolve();
if (result == null || PyBuiltinCache.getInstance(node).isBuiltin(result)) {
registerProblem(node, "Comparison with None performed with equality operators", new ComparisonWithNoneQuickFix());
registerProblem(node, PyPsiBundle.message("INSP.comparison.with.none.performed.with.equality.operators"), new ComparisonWithNoneQuickFix());
}
}
}
@@ -2,6 +2,7 @@
package com.jetbrains.python.quickFixes;
import com.intellij.testFramework.LightProjectDescriptor;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyQuickFixTestCase;
import com.jetbrains.python.inspections.PyAsyncCallInspection;
import com.jetbrains.python.psi.LanguageLevel;
@@ -11,13 +12,13 @@ public class PyAsyncCallQuickFixTest extends PyQuickFixTestCase {
// PY-17292
public void testAddAwaitBeforeCall() {
doQuickFixTest(PyAsyncCallInspection.class, PyAsyncCallInspection.coroutineIsNotAwaited, LanguageLevel.PYTHON35);
doQuickFixTest(PyAsyncCallInspection.class, PyPsiBundle.message("QFIX.coroutine.is.not.awaited"), LanguageLevel.PYTHON35);
}
// PY-17292
public void testAddYieldFromBeforeCall() {
runWithLanguageLevel(LanguageLevel.PYTHON35,
() -> doMultifilesTest(PyAsyncCallInspection.class, PyAsyncCallInspection.coroutineIsNotAwaited,
() -> doMultifilesTest(PyAsyncCallInspection.class, PyPsiBundle.message("QFIX.coroutine.is.not.awaited"),
new String[]{"addYieldFromBeforeCall.py", "asyncio/__init__.py", "asyncio/coroutines.py"}));
}