PyExpression () { final PyAssignmentStatement assignment = PsiTreeUtil.getParentOfType(this, PyAssignmentStatement.class); if (assignment != null) { final List<Pair<PyExpression, PyExpression>> mapping = assignment.getTargetsToValuesMapping(); for (final Pair<PyExpression, PyExpression> pair : mapping) { PyExpression assigned_to = pair.getFirst(); if (assigned_to == this) { return pair.getSecond(); } } } final PyImportElement importElement = PsiTreeUtil.getParentOfType(this, PyImportElement.class); if (importElement != null) { return importElement.getImportReferenceExpression(); } final PyAssignmentExpression assignmentExpression = as(getParent(), PyAssignmentExpression.class); if (assignmentExpression != null) { return assignmentExpression.getAssignedValue(); } return null; }