mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-12369 Code Inspection fails for negative default parameter
This commit is contained in:
@@ -127,11 +127,8 @@ public class PyArgumentEqualDefaultInspection extends PyInspection {
|
||||
}
|
||||
|
||||
private boolean isEqual(PyExpression key, PyExpression defaultValue) {
|
||||
if (key instanceof PyNumericLiteralExpression && defaultValue instanceof PyNumericLiteralExpression) {
|
||||
if (key.getText().equals(defaultValue.getText()))
|
||||
return true;
|
||||
}
|
||||
if (key instanceof PyBinaryExpression && defaultValue instanceof PyBinaryExpression) {
|
||||
if (isBothInstanceOf(key, defaultValue, PyNumericLiteralExpression.class) ||
|
||||
isBothInstanceOf(key, defaultValue, PyPrefixExpression.class) || isBothInstanceOf(key, defaultValue, PyBinaryExpression.class)) {
|
||||
if (key.getText().equals(defaultValue.getText()))
|
||||
return true;
|
||||
}
|
||||
@@ -155,5 +152,11 @@ public class PyArgumentEqualDefaultInspection extends PyInspection {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBothInstanceOf(@NotNull final PyExpression key,
|
||||
@NotNull final PyExpression defaultValue,
|
||||
@NotNull final Class clazz) {
|
||||
return clazz.isInstance(key) && clazz.isInstance(defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,3 +73,9 @@ def a(foo=1*1024):
|
||||
|
||||
a( 1024*1024)
|
||||
|
||||
|
||||
def f1(value=-1):
|
||||
print(value)
|
||||
|
||||
def f2():
|
||||
f1(value =-2)
|
||||
Reference in New Issue
Block a user