diff --git a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java index 032600677dd7..fd83da17d2b5 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java +++ b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.Function; import com.jetbrains.python.PyBundle; import com.jetbrains.python.PyNames; import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache; @@ -131,6 +130,9 @@ public class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor { if (PyAugAssignmentStatementNavigator.getStatementByTarget(element) != null) { continue; } + if (parameterInMethodWithFixedSignature(owner, element)) { + continue; + } if (!myUsedElements.contains(element)) { myUnusedElements.add(element); } @@ -138,6 +140,19 @@ public class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor { } } + private static boolean parameterInMethodWithFixedSignature(@NotNull ScopeOwner owner, @NotNull PsiElement element) { + if (owner instanceof PyFunction && element instanceof PyParameter) { + final PyFunction function = (PyFunction)owner; + final String functionName = function.getName(); + + return !PyNames.INIT.equals(functionName) && + function.getContainingClass() != null && + PyNames.getBuiltinMethods(LanguageLevel.forElement(function)).containsKey(functionName); + } + + return false; + } + private void collectUsedReads(final ScopeOwner owner) { final Instruction[] instructions = ControlFlowCache.getControlFlow(owner).getInstructions(); for (int i = 0; i < instructions.length; i++) { diff --git a/python/testData/inspections/PyUnusedLocalVariableInspection/test.py b/python/testData/inspections/PyUnusedLocalVariableInspection/test.py index 2cfa3c07d5cc..bafdcbfed95e 100644 --- a/python/testData/inspections/PyUnusedLocalVariableInspection/test.py +++ b/python/testData/inspections/PyUnusedLocalVariableInspection/test.py @@ -320,3 +320,12 @@ def test_unused_empty_init_parameter(): # PY-14429 def test_used_local_augmented_assignment(x, y): x += y + + +# PY-19492 +class A: + def __exit__(self, exc_type, exc_val, exc_tb): + print(exc_type) + + def __eq__(self, other): + return False