diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java index 9d770bb36ad0..88e95c33dc33 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java @@ -208,15 +208,21 @@ public class AddCallSuperQuickFix implements LocalQuickFix { } // Required keyword-only parameters + boolean hasKeywordOnlyParams = false; for (PyParameter param : origInfo.getRequiredKeywordOnlyParameters()) { newFunctionParams.add(param.getText()); + hasKeywordOnlyParams = true; } for (PyParameter param : superInfo.getRequiredKeywordOnlyParameters()) { if (!origInfo.getAllParameterNames().contains(param.getName())) { newFunctionParams.add(param.getText()); + hasKeywordOnlyParams = true; } superCallArgs.add(param.getName() + "=" + param.getName()); } + if (starredParam instanceof PySingleStarParameter && !hasKeywordOnlyParams) { + newFunctionParams.remove(newFunctionParams.size() - 1); + } // Optional keyword-only parameters for (PyParameter param : origInfo.getOptionalKeywordOnlyParameters()) { diff --git a/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit.py b/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit.py new file mode 100644 index 000000000000..6fded892bae0 --- /dev/null +++ b/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit.py @@ -0,0 +1,8 @@ +class A: + def __init__(self, a, b=1, *, kw_only=2): + pass + + +class B(A): + def __init__(self): + pass \ No newline at end of file diff --git a/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit_after.py b/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit_after.py new file mode 100644 index 000000000000..e15f93d90fa0 --- /dev/null +++ b/python/testData/inspections/AddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit_after.py @@ -0,0 +1,8 @@ +class A: + def __init__(self, a, b=1, *, kw_only=2): + pass + + +class B(A): + def __init__(self, a): + super().__init__(a) \ No newline at end of file diff --git a/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged.py b/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged.py new file mode 100644 index 000000000000..d831b9373ff6 --- /dev/null +++ b/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged.py @@ -0,0 +1,8 @@ +class A: + def __init__(self, *, a): + pass + + +class B(A): + def __init__(self, a): + pass \ No newline at end of file diff --git a/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged_after.py b/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged_after.py new file mode 100644 index 000000000000..124bbe2b76f8 --- /dev/null +++ b/python/testData/inspections/AddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged_after.py @@ -0,0 +1,8 @@ +class A: + def __init__(self, *, a): + pass + + +class B(A): + def __init__(self, a): + super().__init__(a=a) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java index be13295c0061..d19f8227d9fd 100644 --- a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java @@ -115,6 +115,27 @@ public class Py3QuickFixTest extends PyTestCase { doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true); } + // PY-15867 + public void testAddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit() { + runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() { + @Override + public void run() { + doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true); + } + }); + } + + // PY-15867 + public void testAddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged() { + runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() { + @Override + public void run() { + doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true); + } + }); + } + + // PY-8991 public void testRemoveUnicodePrefixFromGluedStringNodesWithSlash() { runWithLanguageLevel(LanguageLevel.PYTHON32, new Runnable() {