From a0ed2cb7d11dbe87735db74373a1431f8017e74b Mon Sep 17 00:00:00 2001 From: Dmitry Cheryasov Date: Thu, 4 Nov 2010 18:10:00 +0200 Subject: [PATCH] Correctly handle __new__'s first param, staticmethod or not. --- .../PyMethodParametersInspection.java | 23 +++++++++---------- .../PyMethodParametersInspection/expected.xml | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyMethodParametersInspection.java b/python/src/com/jetbrains/python/inspections/PyMethodParametersInspection.java index 54fdd1fc1d2f..74ff3aecb5a9 100644 --- a/python/src/com/jetbrains/python/inspections/PyMethodParametersInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyMethodParametersInspection.java @@ -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 diff --git a/python/testData/inspections/PyMethodParametersInspection/expected.xml b/python/testData/inspections/PyMethodParametersInspection/expected.xml index bcdb702c404c..ca106f831549 100644 --- a/python/testData/inspections/PyMethodParametersInspection/expected.xml +++ b/python/testData/inspections/PyMethodParametersInspection/expected.xml @@ -43,7 +43,7 @@ first_arg.py 65 - Usually first parameter of such methods is named 'cls' + Usually first parameter of such methods is named 'typ' first_arg.py