mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-87502 PyCharm considers Literal[1] not to be equal to Literal[+1]
GitOrigin-RevId: 2e65c2f06e4398a01f7d81aec3eeed636219cb0d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7bfd68309a
commit
cfa611b041
@@ -290,16 +290,21 @@ public class PyEvaluator {
|
||||
}
|
||||
|
||||
private @Nullable Object evaluatePrefix(@NotNull PyPrefixExpression expression) {
|
||||
if (expression.getOperator() == PyTokenTypes.NOT_KEYWORD) {
|
||||
PyElementType operator = expression.getOperator();
|
||||
if (operator == PyTokenTypes.NOT_KEYWORD) {
|
||||
final Boolean value = PyUtil.as(evaluate(expression.getOperand()), Boolean.class);
|
||||
if (value != null) {
|
||||
return !value;
|
||||
}
|
||||
}
|
||||
else if (expression.getOperator() == PyTokenTypes.MINUS) {
|
||||
else if (operator == PyTokenTypes.MINUS || operator == PyTokenTypes.PLUS) {
|
||||
final Number number = PyUtil.as(evaluate(expression.getOperand()), Number.class);
|
||||
if (number != null) {
|
||||
return fromBigInteger(toBigInteger(number).negate());
|
||||
var bigInt = toBigInteger(number);
|
||||
if (operator == PyTokenTypes.MINUS) {
|
||||
bigInt = bigInt.negate();
|
||||
}
|
||||
return fromBigInteger(bigInt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,6 +254,12 @@ public class PyEvaluatorTest extends PyTestCase {
|
||||
assertTrue(byExpression("2 != 1", Boolean.class));
|
||||
}
|
||||
|
||||
public void testPositiveNumberLiteral() {
|
||||
assertEquals(Integer.valueOf(5), byExpression("+5", Integer.class));
|
||||
assertEquals(Long.valueOf(Long.MAX_VALUE), byExpression("+" + Long.MAX_VALUE, Long.class));
|
||||
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE), byExpression("+" + BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE), BigInteger.class));
|
||||
}
|
||||
|
||||
public void testBooleanOperators() {
|
||||
assertTrue(byExpression("True and True", Boolean.class));
|
||||
assertTrue(byExpression("True or False", Boolean.class));
|
||||
|
||||
Reference in New Issue
Block a user