@Nullable private static PyGenericType getGenericType( @NotNull PsiElement element, @NotNull Context context) { if (element instanceof PyCallExpression) { final PyCallExpression assignedCall = (PyCallExpression) element; final PyExpression callee = assignedCall.getCallee(); if (callee != null) { final Collection<String> calleeQNames = resolveToQualifiedNames(callee, context.getTypeContext()); if (calleeQNames.contains("typing.TypeVar")) { final PyExpression[] arguments = assignedCall.getArguments(); if (arguments.length > 0) { final PyExpression firstArgument = arguments[0]; if (firstArgument instanceof PyStringLiteralExpression) { final String name = ((PyStringLiteralExpression) firstArgument).getStringValue(); if (name != null) { return new PyGenericType(name, getGenericTypeBound(arguments, context)); } } } } } } return null; }
private static boolean isValidIntroduceVariant(PsiElement element) { final PyCallExpression call = PsiTreeUtil.getParentOfType(element, PyCallExpression.class); if (call != null && PsiTreeUtil.isAncestor(call.getCallee(), element, false)) { return false; } return true; }
@Override public void visitPyCallExpression(final PyCallExpression node) { // TODO: refactor, messy code final PyExpression callee = node.getCallee(); if (callee != null) { final PsiReference calleeRef = callee.getReference(); if (calleeRef != null) { final PsiElement calleeDeclaration = calleeRef.resolve(); if (calleeDeclaration instanceof PyFunction) { final PyFunction calleeFunction = (PyFunction) calleeDeclaration; final PyClass clazz = calleeFunction.getContainingClass(); if (clazz != null) { if (PyUtil.isInit(calleeFunction)) { return; // Init call should not be marked as dependency } myResult.putValue(clazz, calleeFunction); } } } } }