Revert of "IDEA-CR-17950: True and False are now always PyBooleanLiteralExpressions" because of "Restored None, False, True as non-keywords (reserved words) in PY2"

This commit is contained in:
Ilya.Kazakevich
2017-04-17 22:25:48 +03:00
parent a63650f4d8
commit 9d0d776478
@@ -67,8 +67,9 @@ public class PyEvaluator {
if (expr instanceof PySequenceExpression) {
return evaluateSequenceExpression((PySequenceExpression)expr);
}
if (expr instanceof PyBoolLiteralExpression) {
return ((PyBoolLiteralExpression)expr).getValue();
final Boolean booleanExpression = getBooleanExpression(expr);
if (booleanExpression != null) { // support bool
return booleanExpression;
}
if (expr instanceof PyCallExpression) {
return evaluateCall((PyCallExpression)expr);
@@ -93,6 +94,32 @@ public class PyEvaluator {
return null;
}
/**
* TODO: Move to PyExpression? PyUtil?
* True/False is bool literal in Py3K, but reference in Python2.
*
* @param expression expression to check
* @return true if expression is boolean
*/
@Nullable
private static Boolean getBooleanExpression(@NotNull final PyExpression expression) {
final boolean py3K = LanguageLevel.forElement(expression).isPy3K();
if ((expression instanceof PyBoolLiteralExpression)) {
return ((PyBoolLiteralExpression)expression).getValue();
}
if ((!py3K && (expression instanceof PyReferenceExpression))) {
final String text = ((PyQualifiedExpression)expression).getReferencedName(); // Ref in Python2
if (PyNames.TRUE.equals(text)) {
return true;
}
if (PyNames.FALSE.equals(text)) {
return false;
}
}
return null;
}
/**
* Evaluates some sequence (tuple, list)
*