From 2d0e96c4284450ede61e0494e1422d8d4192651f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=B0=E8=A8=80?= Date: Mon, 29 Jun 2026 13:14:40 +0800 Subject: [PATCH 1/2] feat(conversions): add input validation and lowercase support to excel_title_to_column --- conversions/excel_title_to_column.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/conversions/excel_title_to_column.py b/conversions/excel_title_to_column.py index d77031ec26f2..54e1a16d2972 100644 --- a/conversions/excel_title_to_column.py +++ b/conversions/excel_title_to_column.py @@ -12,8 +12,25 @@ def excel_title_to_column(column_title: str) -> int: 28 >>> excel_title_to_column("Z") 26 + >>> excel_title_to_column("a") + 1 + >>> excel_title_to_column("ab") + 28 + >>> excel_title_to_column("") + Traceback (most recent call last): + ... + ValueError: Column title must be a non-empty string containing only alphabetic characters. + >>> excel_title_to_column("A1") + Traceback (most recent call last): + ... + ValueError: Column title must be a non-empty string containing only alphabetic characters. """ - assert column_title.isupper() + if not column_title or not column_title.isalpha(): + raise ValueError( + "Column title must be a non-empty string containing only alphabetic characters." + ) + + column_title = column_title.upper() answer = 0 index = len(column_title) - 1 power = 0 From 7697978908550b50a7becbdb58b0f3fb6106c4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=B0=E8=A8=80?= Date: Mon, 29 Jun 2026 13:17:36 +0800 Subject: [PATCH 2/2] style(conversions): shorten ValueError message to comply with ruff E501 line length limit --- conversions/excel_title_to_column.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/conversions/excel_title_to_column.py b/conversions/excel_title_to_column.py index 54e1a16d2972..8245de3f28f3 100644 --- a/conversions/excel_title_to_column.py +++ b/conversions/excel_title_to_column.py @@ -19,16 +19,14 @@ def excel_title_to_column(column_title: str) -> int: >>> excel_title_to_column("") Traceback (most recent call last): ... - ValueError: Column title must be a non-empty string containing only alphabetic characters. + ValueError: Column title must contain only alphabetic characters. >>> excel_title_to_column("A1") Traceback (most recent call last): ... - ValueError: Column title must be a non-empty string containing only alphabetic characters. + ValueError: Column title must contain only alphabetic characters. """ if not column_title or not column_title.isalpha(): - raise ValueError( - "Column title must be a non-empty string containing only alphabetic characters." - ) + raise ValueError("Column title must contain only alphabetic characters.") column_title = column_title.upper() answer = 0