Correctly handle __new__'s first param, staticmethod or not.

This commit is contained in:
Dmitry Cheryasov
2010-11-04 18:10:00 +02:00
parent f26fa89a1a
commit a0ed2cb7d1
2 changed files with 12 additions and 13 deletions
@@ -111,18 +111,8 @@ public class PyMethodParametersInspection extends PyInspection {
return;
}
}
// TODO: check for style settings
String CLS = "cls";
if (flags.contains(CLASSMETHOD) || isSpecialMetaclassMethod) {
if (!CLS.equals(pname)) {
registerProblem(
PyUtil.sure(params[0].getNode()).getPsi(),
PyBundle.message("INSP.usually.named.$0", CLS),
new RenameParameterQuickFix(CLS)
);
}
}
else if (isMetaclassMethod && PyNames.NEW.equals(method_name)) {
String CLS = "cls"; // TODO: move to style settings
if (isMetaclassMethod && PyNames.NEW.equals(method_name)) {
final String[] POSSIBLE_PARAM_NAMES = {"typ", "meta"}; // TODO: move to style settings
if (!among(pname, POSSIBLE_PARAM_NAMES)) {
registerProblem(
@@ -132,6 +122,15 @@ public class PyMethodParametersInspection extends PyInspection {
);
}
}
else if (flags.contains(CLASSMETHOD) || isSpecialMetaclassMethod || PyNames.NEW.equals(method_name)) {
if (!CLS.equals(pname)) {
registerProblem(
PyUtil.sure(params[0].getNode()).getPsi(),
PyBundle.message("INSP.usually.named.$0", CLS),
new RenameParameterQuickFix(CLS)
);
}
}
else if (!is_staticmethod && !first_param.isPositionalContainer() && !PyNames.CANONICAL_SELF.equals(pname)) {
if (isMetaclassMethod && CLS.equals(pname)) {
return; // accept either 'self' or 'cls' for all methods in metaclass
@@ -43,7 +43,7 @@
<problem>
<file>first_arg.py</file>
<line>65</line>
<description>Usually first parameter of such methods is named 'cls'</description>
<description>Usually first parameter of such methods is named 'typ'</description>
</problem>
<problem>
<file>first_arg.py</file>