mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Introduce method to determine if decorator updates attributes (PY-27964)
This commit is contained in:
+2
-1
@@ -826,7 +826,8 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
}
|
||||
if (type instanceof PyFunctionTypeImpl) {
|
||||
final PyCallable callable = ((PyFunctionTypeImpl)type).getCallable();
|
||||
if (callable instanceof PyFunction && PyKnownDecoratorUtil.hasUnknownDecorator((PyFunction)callable, myTypeEvalContext)) {
|
||||
if (callable instanceof PyFunction &&
|
||||
PyKnownDecoratorUtil.hasUnknownOrUpdatingAttributesDecorator((PyFunction)callable, myTypeEvalContext)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,21 @@ public class PyKnownDecoratorUtil {
|
||||
return !allDecoratorsAreKnown(decoratable, decorators) || decorators.contains(UNITTEST_MOCK_PATCH);
|
||||
}
|
||||
|
||||
public static boolean hasUnknownOrUpdatingAttributesDecorator(@NotNull PyDecoratable decoratable, @NotNull TypeEvalContext context) {
|
||||
final List<KnownDecorator> decorators = getKnownDecorators(decoratable, context);
|
||||
|
||||
if (!allDecoratorsAreKnown(decoratable, decorators)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ContainerUtil.exists(
|
||||
decorators,
|
||||
d ->
|
||||
d == FUNCTOOLS_LRU_CACHE || // cache_clear, cache_info
|
||||
d == FUNCTOOLS_SINGLEDISPATCH // dispatch, register, registry
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean allDecoratorsAreKnown(@NotNull PyDecoratable element, @NotNull List<KnownDecorator> decorators) {
|
||||
final PyDecoratorList decoratorList = element.getDecoratorList();
|
||||
return decoratorList == null ? decorators.isEmpty() : decoratorList.getDecorators().length == decorators.size();
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
from functools import singledispatch
|
||||
|
||||
|
||||
@singledispatch
|
||||
def to_description(ob):
|
||||
return str(ob)
|
||||
|
||||
|
||||
@to_description.register(type(None))
|
||||
def none_to_description(_):
|
||||
return '–'
|
||||
|
||||
|
||||
@to_description.register(bool)
|
||||
def bool_to_description(b):
|
||||
return '✓' if b else ''
|
||||
+5
@@ -265,4 +265,9 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase
|
||||
public void testNamespacePackageRedundantUnion() {
|
||||
doMultiFileTest("a.py", Arrays.asList("root1", "root2"));
|
||||
}
|
||||
|
||||
// PY-27964
|
||||
public void testUsingFunctoolsSingledispatch() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user