From af95791857b8d6838a0879e10909c3c39d123e1e Mon Sep 17 00:00:00 2001 From: Milad Khoshdel Date: Fri, 11 Sep 2026 21:40:25 +0330 Subject: [PATCH] refactor: modernize input type validation --- luhn.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/luhn.py b/luhn.py index c40ae14..480805a 100644 --- a/luhn.py +++ b/luhn.py @@ -2,9 +2,7 @@ from __future__ import annotations -from typing import Union - -NumberLike = Union[str, int] +NumberLike = str | int REMOVE_CHARS = " -./\\," DIGIT_CLEANUP_TABLE = str.maketrans("", "", REMOVE_CHARS) @@ -12,7 +10,7 @@ def _digits(value: NumberLike) -> str: """Return only digits, allowing spaces, hyphens, dots, slashes, backslashes, and commas as separators.""" if isinstance(value, bool) or not isinstance(value, (str, int)): - raise ValueError("value must be a string or non-boolean integer") + raise TypeError("value must be a string or non-boolean integer") cleaned = str(value).strip().translate(DIGIT_CLEANUP_TABLE)