From 9602a24b02383d02f131fd3d8a7b83bb00c25fcb Mon Sep 17 00:00:00 2001 From: Morgan Bartholomew Date: Thu, 19 Mar 2026 21:27:44 +1000 Subject: [PATCH] misc python: reject `None` literals in `PyLiteralType.classOfAcceptableLiteral` GitOrigin-RevId: e3da34795615abbf1d409e53757fd82ae4ba2a6e --- .../python/psi/types/PyLiteralType.kt | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyLiteralType.kt b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyLiteralType.kt index 237e6b7c31cd..ba96d51c9a30 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyLiteralType.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyLiteralType.kt @@ -273,24 +273,19 @@ class PyLiteralType private constructor(cls: PyClass, val expression: PyExpressi } private fun classOfAcceptableLiteral(expression: PyExpression, context: TypeEvalContext, index: Boolean): PyClass? { - return when { - expression is PyNumericLiteralExpression -> if (expression.isIntegerLiteral) getPyClass(expression, context) else null - - expression is PyStringLiteralExpression -> - if (isAcceptableStringLiteral(expression, index)) getPyClass(expression, context) else null - - expression is PyEllipsisLiteralExpression -> null - - expression is PyLiteralExpression -> getPyClass(expression, context) - - expression is PyPrefixExpression && (expression.operator == PyTokenTypes.PLUS || expression.operator == PyTokenTypes.MINUS) -> { + return when (expression) { + is PyNumericLiteralExpression -> if (expression.isIntegerLiteral) getPyClass(expression, context) else null + is PyStringLiteralExpression -> if (isAcceptableStringLiteral(expression, index)) getPyClass(expression, context) else null + is PyEllipsisLiteralExpression, is PyNoneLiteralExpression -> null + is PyLiteralExpression -> getPyClass(expression, context) + is PyPrefixExpression if (expression.operator == PyTokenTypes.PLUS || expression.operator == PyTokenTypes.MINUS) -> { val operand = expression.operand if (operand is PyNumericLiteralExpression && operand.isIntegerLiteral) getPyClass(operand, context) else null } - - PyEvaluator.getBooleanLiteralValue(expression) != null -> getPyClass(expression, context) - - else -> null + else -> if (PyEvaluator.getBooleanLiteralValue(expression) != null) { + getPyClass(expression, context) + } + else null } }