i18n: Extract messages from several Python inspections

GitOrigin-RevId: 2984a5da8f02308dc5c303fdb37ebb1015bc25c1
This commit is contained in:
Mikhail Golubev
2020-08-20 11:49:39 +00:00
committed by intellij-monorepo-bot
parent 91b2855a68
commit 4365fe225c
11 changed files with 56 additions and 27 deletions
@@ -131,7 +131,7 @@
<localInspection language="Python" shortName="PyDataclassInspection" suppressId="PyDataclass" bundle="messages.PyPsiBundle" key="INSP.NAME.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"/>
<localInspection language="Python" shortName="PyDictDuplicateKeysInspection" suppressId="PyDictDuplicateKeys" bundle="messages.PyPsiBundle" key="INSP.NAME.duplicate.keys" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDictDuplicateKeysInspection"/>
<localInspection language="Python" shortName="PyDunderSlotsInspection" suppressId="PyDunderSlots" bundle="messages.PyPsiBundle" key="INSP.dunder.slots" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDunderSlotsInspection"/>
<localInspection language="Python" shortName="PyDunderSlotsInspection" suppressId="PyDunderSlots" bundle="messages.PyPsiBundle" key="INSP.NAME.dunder.slots" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDunderSlotsInspection"/>
<localInspection language="Python" shortName="PyExceptClausesOrderInspection" suppressId="PyExceptClausesOrder" bundle="messages.PyPsiBundle" key="INSP.NAME.bad.except.clauses.order" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyExceptClausesOrderInspection"/>
<localInspection language="Python" shortName="PyFinalInspection" suppressId="PyFinal" bundle="messages.PyPsiBundle" key="INSP.final.classes.methods.and.variables" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyFinalInspection"/>
<localInspection language="Python" shortName="PyFromFutureImportInspection" suppressId="PyFromFutureImport" bundle="messages.PyPsiBundle" key="INSP.NAME.from.future.import" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyFromFutureImportInspection"/>
@@ -171,7 +171,7 @@
<localInspection language="Python" shortName="PySetFunctionToLiteralInspection" suppressId="PySetFunctionToLiteral" bundle="messages.PyPsiBundle" key="INSP.NAME.set.function.to.literal" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PySetFunctionToLiteralInspection"/>
<localInspection language="Python" shortName="PyDecoratorInspection" suppressId="PyDecorator" bundle="messages.PyPsiBundle" key="INSP.NAME.decorator.outside.class" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDecoratorInspection"/>
<localInspection language="Python" shortName="PyTypeCheckerInspection" suppressId="PyTypeChecker" bundle="messages.PyPsiBundle" key="INSP.type.checker" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyTypeCheckerInspection"/>
<localInspection language="Python" shortName="PyDeprecationInspection" suppressId="PyDeprecation" bundle="messages.PyPsiBundle" key="INSP.deprecated.function.class.or.module" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDeprecationInspection"/>
<localInspection language="Python" shortName="PyDeprecationInspection" suppressId="PyDeprecation" bundle="messages.PyPsiBundle" key="INSP.NAME.deprecated.function.class.or.module" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyDeprecationInspection"/>
<localInspection language="Python" shortName="PyMandatoryEncodingInspection" suppressId="PyMandatoryEncoding" bundle="messages.PyPsiBundle" key="INSP.mandatory.encoding" groupKey="INSP.GROUP.python" enabledByDefault="false" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyMandatoryEncodingInspection"/>
<localInspection language="Python" shortName="PyClassHasNoInitInspection" suppressId="PyClassHasNoInit" bundle="messages.PyPsiBundle" key="INSP.class.has.no.init" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyClassHasNoInitInspection"/>
<localInspection language="Python" shortName="PyNoneFunctionAssignmentInspection" suppressId="PyNoneFunctionAssignment" bundle="messages.PyPsiBundle" key="INSP.assigning.function.call.that.doesnt.return.anything" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyNoneFunctionAssignmentInspection"/>
@@ -442,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.dunder.slots=Definition of __slots__ in a class
INSP.final.classes.methods.and.variables=Final classes, methods and variables
INSP.global.undefined=Global variable is undefined at the module level
INSP.inconsistent.indentation=Inconsistent indentation
@@ -487,7 +486,6 @@ INSP.stub.packages.compatibility.incompatible.packages.message=''{0}{1}{2}'' is
INSP.arguments.not.declared.but.provided.by.decorator=Following arguments are not declared but provided by decorator: {0}
INSP.abstract.class=Class must implement all abstract methods
INSP.assigning.function.call.that.doesnt.return.anything=Assigning function call that doesn't return anything
INSP.deprecated.function.class.or.module=Deprecated function, class or module
INSP.mandatory.encoding=No encoding specified for file
INSP.missing.type.hints=Missing type hinting for function definition
INSP.overloads.in.regular.python.files=Overloads in regular Python files
@@ -603,12 +601,15 @@ INSP.classic.class.usage.old.style.class.ancestors=Old-style class, because all
# PyExceptionInheritance
INSP.NAME.exception.not.inherit=Exception doesn't inherit from standard ''Exception'' class
INSP.exception.inheritance.exception.does.not.inherit.from.base.exception.class=Exception doesn't inherit from base 'Exception' class
# PyDefaultArgumentInspection
INSP.NAME.default.argument=Default argument is mutable
INSP.default.arguments.default.argument.value.mutable=Default argument value is mutable
# PyDocstringTypesInspection
INSP.NAME.docstring.types=Type in docstring doesn't match inferred type
INSP.docstring.types.dynamically.inferred.type.does.not.match.specified.type=Dynamically inferred type ''{0}'' doesn''t match specified type ''{1}''
# PyStatementEffectInspection
INSP.NAME.statement.effect=Statement has no effect
@@ -734,6 +735,7 @@ INSP.NAME.set.function.to.literal=Function call can be replaced with set literal
# PyDecoratorInspection
INSP.NAME.decorator.outside.class=Class specific decorator on method outside class
INSP.decorators.method.only.decorator.on.method.outside.class=Decorator {0} on method outside class
# PyPackageRequirementsInspection
INSP.NAME.requirements=Package requirements
@@ -786,9 +788,11 @@ INSP.comparison.with.none.performed.with.equality.operators=Comparison with None
# PyDictCreationInspection
INSP.NAME.dict.creation=Dictionary creation could be rewritten by dictionary literal
INSP.dict.creation.this.dictionary.creation.could.be.rewritten.as.dictionary.literal=This dictionary creation could be rewritten as a dictionary literal
# PyDictDuplicateKeysInspection
INSP.NAME.duplicate.keys=Dictionary contains duplicate keys
INSP.duplicate.keys.dictionary.contains.duplicate.keys=Dictionary contains duplicate keys ''{0}''
# PyFromFutureImportInspection
INSP.NAME.from.future.import=from __future__ import must be the first executable statement
@@ -906,6 +910,14 @@ INSP.python.trailing.suffix.not.support=Python does not support a trailing ''{0}
# PyInterpreterInspection
python.sdk.no.interpreter.configured.owner=No Python interpreter configured for the {0}
# PyDeprecationInspection
INSP.NAME.deprecated.function.class.or.module=Deprecated function, class or module
INSP.deprecation.abc.decorator.deprecated.use.alternative=''{0}'' is deprecated since Python 3.3. Use ''{1}'' with ''{2}'' instead
INSP.NAME.dunder.slots=Definition of __slots__ in a class
INSP.dunder.slots.name.in.slots.conflicts.with.class.variable=''{0}'' in __slots__ conflicts with class variable
INSP.dunder.slots.class.object.attribute.read.only=''{0}'' object attribute ''{1}'' is read-only
# PyInspectionsSuppressor
INSP.python.suppressor.suppress.for.function=Suppress for function
INSP.python.suppressor.suppress.for.class=Suppress for class
@@ -18,6 +18,7 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElementVisitor;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.RemoveDecoratorQuickFix;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyDecorator;
@@ -59,7 +60,8 @@ public class PyDecoratorInspection extends PyInspection {
for (PyDecorator decorator : decorators.getDecorators()) {
String name = decorator.getText();
if (name.equals("@classmethod") || name.equals("@staticmethod"))
registerProblem(decorator, "Decorator " + name + " on method outside class", new RemoveDecoratorQuickFix());
registerProblem(decorator, PyPsiBundle.message("INSP.decorators.method.only.decorator.on.method.outside.class", name),
new RemoveDecoratorQuickFix());
}
}
}
@@ -18,6 +18,7 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElementVisitor;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.PyDefaultArgumentQuickFix;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.PyNamedParameter;
@@ -47,7 +48,8 @@ public class PyDefaultArgumentInspection extends PyInspection {
public void visitPyNamedParameter(PyNamedParameter node) {
final PyExpression defaultValue = node.getDefaultValue();
if (PyUtil.isForbiddenMutableDefault(defaultValue, myTypeEvalContext)) {
registerProblem(defaultValue, "Default argument value is mutable", new PyDefaultArgumentQuickFix());
registerProblem(defaultValue, PyPsiBundle.message("INSP.default.arguments.default.argument.value.mutable"),
new PyDefaultArgumentQuickFix());
}
}
}
@@ -19,9 +19,11 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator;
import com.jetbrains.python.pyi.PyiUtil;
@@ -59,7 +61,7 @@ public class PyDeprecationInspection extends PyInspection {
final PsiElement element = importStatement.resolveImportSource();
if (resolveResult != null && element != resolveResult.getContainingFile()) return;
}
String deprecationMessage = null;
@NlsSafe String deprecationMessage = null;
if (resolveResult instanceof PyFunction) {
deprecationMessage = ((PyFunction)resolveResult).getDeprecationMessage();
}
@@ -100,8 +102,10 @@ public class PyDeprecationInspection extends PyInspection {
}
final KnownDecorator abcAbsMethod = KnownDecorator.ABC_ABSTRACTMETHOD;
final String message = "'" + deprecated.getQualifiedName() + "' is deprecated since Python 3.3. " +
"Use '" + builtin.getQualifiedName() + "' with '" + abcAbsMethod.getQualifiedName() + "' instead.";
final String message = PyPsiBundle.message("INSP.deprecation.abc.decorator.deprecated.use.alternative",
deprecated.getQualifiedName(),
builtin.getQualifiedName(),
abcAbsMethod.getQualifiedName());
registerProblem(decorator, message, ProblemHighlightType.LIKE_DEPRECATED);
}
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.DictCreationQuickFix;
import com.jetbrains.python.psi.*;
import org.jetbrains.annotations.NotNull;
@@ -68,7 +69,9 @@ public class PyDictCreationInspection extends PyInspection {
if (targets == null)
return;
if (!targets.isEmpty()) {
registerProblem(node, "This dictionary creation could be rewritten as a dictionary literal", new DictCreationQuickFix(node));
registerProblem(node,
PyPsiBundle.message("INSP.dict.creation.this.dictionary.creation.could.be.rewritten.as.dictionary.literal"),
new DictCreationQuickFix(node));
break;
}
statement = PsiTreeUtil.getNextSiblingOfType(assignmentStatement, PyStatement.class);
@@ -19,11 +19,13 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.util.containers.MultiMap;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.PyRemoveDictKeyQuickFix;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyBuiltinCache;
@@ -127,12 +129,13 @@ public class PyDictDuplicateKeysInspection extends PyInspection {
private void registerProblems(@NotNull MultiMap<String, PsiElement> keyValueAndKeys, LocalQuickFix @NotNull ... quickFixes) {
for (Map.Entry<String, Collection<PsiElement>> entry : keyValueAndKeys.entrySet()) {
final String keyValue = entry.getKey();
final @NlsSafe String keyValue = entry.getKey();
final Collection<PsiElement> keys = entry.getValue();
if (keys.size() > 1) {
for (PsiElement key : keys) {
registerProblem(key, "Dictionary contains duplicate keys '" + unwrapStringKey(keyValue) + "'", quickFixes);
String unquotedKey = unwrapStringKey(keyValue);
registerProblem(key, PyPsiBundle.message("INSP.duplicate.keys.dictionary.contains.duplicate.keys", unquotedKey), quickFixes);
}
}
}
@@ -3,6 +3,7 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.SmartPointerManager;
@@ -69,16 +70,14 @@ public class PyDocstringTypesInspection extends PyInspection {
}
for (String param : docString.getParameters()) {
Substring type = docString.getParamTypeSubstring(param);
@NlsSafe Substring type = docString.getParamTypeSubstring(param);
if (type != null) {
String dynamicType = signature.getArgTypeQualifiedName(param);
if (dynamicType != null) {
String dynamicTypeShortName = getShortestImportableName(function, dynamicType);
@NlsSafe String dynamicTypeShortName = getShortestImportableName(function, dynamicType);
if (!match(function, dynamicType, type.getValue())) {
registerProblem(node, "Dynamically inferred type '" +
dynamicTypeShortName +
"' doesn't match specified type '" +
type + "'",
registerProblem(node, PyPsiBundle.message("INSP.docstring.types.dynamically.inferred.type.does.not.match.specified.type",
dynamicTypeShortName, type),
ProblemHighlightType.WEAK_WARNING, null, type.getTextRange(),
new ChangeTypeQuickFix(param, type, dynamicTypeShortName, node)
);
@@ -5,6 +5,7 @@ import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElementVisitor
import com.jetbrains.python.PyNames
import com.jetbrains.python.PyPsiBundle
import com.jetbrains.python.psi.*
import com.jetbrains.python.psi.impl.PyPsiUtils
import com.jetbrains.python.psi.types.PyClassType
@@ -57,7 +58,7 @@ class PyDunderSlotsInspection : PyInspection() {
val classAttribute = pyClass.findClassAttribute(name, false, myTypeEvalContext)
if (classAttribute != null && classAttribute.hasAssignedValue()) {
registerProblem(slot, "'$name' in __slots__ conflicts with class variable")
registerProblem(slot, PyPsiBundle.message("INSP.dunder.slots.name.in.slots.conflicts.with.class.variable", name))
}
}
@@ -71,7 +72,7 @@ class PyDunderSlotsInspection : PyInspection() {
val qualifierType = myTypeEvalContext.getType(qualifier)
if (qualifierType is PyClassType && !qualifierType.isAttributeWritable(targetName, myTypeEvalContext)) {
registerProblem(target, "'${qualifierType.name}' object attribute '$targetName' is read-only")
registerProblem(target, PyPsiBundle.message("INSP.dunder.slots.class.object.attribute.read.only", qualifierType.name, targetName))
}
}
}
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiPolyVariantReference;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.inspections.quickfix.PyAddExceptionSuperClassQuickFix;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.types.PyClassLikeType;
@@ -67,7 +68,9 @@ public class PyExceptionInheritInspection extends PyInspection {
return;
}
}
registerProblem(expression, "Exception doesn't inherit from base 'Exception' class", new PyAddExceptionSuperClassQuickFix());
registerProblem(expression,
PyPsiBundle.message("INSP.exception.inheritance.exception.does.not.inherit.from.base.exception.class"),
new PyAddExceptionSuperClassQuickFix());
}
}
}
@@ -2,7 +2,7 @@ import abc
class A(metaclass=abc.ABCMeta):
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead.">@abc.abstractproperty</warning>
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead">@abc.abstractproperty</warning>
def prop(self):
pass
@@ -11,7 +11,7 @@ from abc import abstractproperty
class B(metaclass=abc.ABCMeta):
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead.">@abstractproperty</warning>
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead">@abstractproperty</warning>
def prop(self):
pass
@@ -20,7 +20,7 @@ from abc import abstractproperty as ap
class C(metaclass=abc.ABCMeta):
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead.">@ap</warning>
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead">@ap</warning>
def prop(self):
pass
@@ -29,16 +29,16 @@ import abc as foo
class D(metaclass=abc.ABCMeta):
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead.">@foo.abstractproperty</warning>
<warning descr="'abc.abstractproperty' is deprecated since Python 3.3. Use 'property' with 'abc.abstractmethod' instead">@foo.abstractproperty</warning>
def prop(self):
pass
class A:
<warning descr="'abc.abstractclassmethod' is deprecated since Python 3.3. Use 'classmethod' with 'abc.abstractmethod' instead.">@abc.abstractclassmethod</warning>
<warning descr="'abc.abstractclassmethod' is deprecated since Python 3.3. Use 'classmethod' with 'abc.abstractmethod' instead">@abc.abstractclassmethod</warning>
def foo(cls):
pass
<warning descr="'abc.abstractstaticmethod' is deprecated since Python 3.3. Use 'staticmethod' with 'abc.abstractmethod' instead.">@abc.abstractstaticmethod</warning>
<warning descr="'abc.abstractstaticmethod' is deprecated since Python 3.3. Use 'staticmethod' with 'abc.abstractmethod' instead">@abc.abstractstaticmethod</warning>
def bar():
pass