RegexpMethodDescriptor (@Nullable PsiElement element) { if (element == null || !(ScopeUtil.getScopeOwner(element) instanceof PyFile) || !ArrayUtil.contains(element.getContainingFile().getName(), "re.py", "re.pyi") || !(element instanceof PyFunction)) { return null; } final String functionName = ((PyFunction)element).getName(); return myDescriptors .stream() .filter(descriptor -> descriptor.methodName.equals(functionName)) .findAny() .orElse(null); }