mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Check original parameter default value if stub one is ellipsis (PY-30335)
This commit is contained in:
@@ -15,6 +15,7 @@ import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.types.PyCallableParameter;
|
||||
import com.jetbrains.python.psi.types.PyClassType;
|
||||
import com.jetbrains.python.pyi.PyiUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -103,7 +104,7 @@ public class PyArgumentEqualDefaultInspection extends PyInspection {
|
||||
if (mapping == null) return;
|
||||
final Set<PyExpression> problemElements = new HashSet<>();
|
||||
for (Map.Entry<PyExpression, PyCallableParameter> e : mapping.getMappedParameters().entrySet()) {
|
||||
final PyExpression defaultValue = e.getValue().getDefaultValue();
|
||||
final PyExpression defaultValue = findDefaultValue(mapping, e.getValue());
|
||||
if (defaultValue != null) {
|
||||
PyExpression key = e.getKey();
|
||||
if (key instanceof PyKeywordArgument && ((PyKeywordArgument)key).getValueExpression() != null) {
|
||||
@@ -128,6 +129,30 @@ public class PyArgumentEqualDefaultInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PyExpression findDefaultValue(@NotNull PyCallExpression.PyArgumentsMapping mapping,
|
||||
@NotNull PyCallableParameter parameter) {
|
||||
final String name = parameter.getName();
|
||||
final PyExpression value = parameter.getDefaultValue();
|
||||
|
||||
if (name == null || !(value instanceof PyNoneLiteralExpression) || !((PyNoneLiteralExpression)value).isEllipsis()) return value;
|
||||
|
||||
final PyCallExpression.PyMarkedCallee markedCallee = mapping.getMarkedCallee();
|
||||
if (markedCallee == null) return value;
|
||||
|
||||
final PyCallable callable = markedCallee.getElement();
|
||||
if (callable == null) return value;
|
||||
|
||||
if (PyiUtil.isInsideStub(callable)) {
|
||||
final PyCallable originalCallable = PyiUtil.stubToOriginal(callable, PyCallable.class);
|
||||
|
||||
final PyNamedParameter originalParameter = originalCallable.getParameterList().findParameterByName(name);
|
||||
if (originalParameter != null) return originalParameter.getDefaultValue();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private boolean isEqual(PyExpression key, PyExpression defaultValue) {
|
||||
if (isBothInstanceOf(key, defaultValue, PyNumericLiteralExpression.class) ||
|
||||
isBothInstanceOf(key, defaultValue, PyPrefixExpression.class) ||
|
||||
|
||||
@@ -34,7 +34,7 @@ class C(object):
|
||||
def delx(self):
|
||||
del self._x
|
||||
|
||||
x = property(getx, None, fdel = delx, doc = "I'm the 'x' property.")
|
||||
x = property(getx, <weak_warning descr="Argument equals to default parameter value">None</weak_warning>, fdel = delx, doc = "I'm the 'x' property.")
|
||||
|
||||
|
||||
# PY-3455
|
||||
@@ -85,4 +85,7 @@ def decorator(arg='baz'):
|
||||
|
||||
@decorator(<weak_warning descr="Argument equals to default parameter value">arg='baz'</weak_warning>)
|
||||
def f<error descr="'(' expected">:</error>
|
||||
pass
|
||||
pass
|
||||
|
||||
with open('file', <weak_warning descr="Argument equals to default parameter value">None</weak_warning>) as file:
|
||||
pass
|
||||
Reference in New Issue
Block a user