diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 0fc5408..d7512d3 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - name: Check out repository diff --git a/README.md b/README.md index baeb59e..daacb20 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ lengths, or whether an identifier is real. ## Requirements -- Python 3.8+ +- Python 3.10+ - No third-party packages ## Quick Start @@ -95,8 +95,9 @@ space - . / \ , After normalization, the value must contain at least one digit and no other characters. `checksum`, `calculate_check_digit`, and `append_check_digit` raise -`ValueError` for invalid input. `is_valid` catches that error and returns -`False`, which makes it convenient for validation checks. +`ValueError` for malformed strings and `TypeError` for unsupported input types. +`is_valid` catches both errors and returns `False`, which makes it convenient +for validation checks. ## Examples diff --git a/luhn.py b/luhn.py index c40ae14..a68b4a0 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) @@ -51,7 +49,7 @@ def is_valid(value: NumberLike) -> bool: try: is_valid_checksum = checksum(value) == 0 - except ValueError: + except (TypeError, ValueError): return False return is_valid_checksum diff --git a/pyproject.toml b/pyproject.toml index ce924c7..bff3f5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] name = "luhn-algorithm" version = "0.1.0" -requires-python = ">=3.14" +requires-python = ">=3.10" dependencies = [] diff --git a/test_luhn.py b/test_luhn.py index b5d0d18..5b0c8ba 100644 --- a/test_luhn.py +++ b/test_luhn.py @@ -38,7 +38,7 @@ def test_rejects_unsupported_types(self): self.assertFalse(is_valid(value)) for function in (checksum, calculate_check_digit, append_check_digit): - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): function(value) diff --git a/uv.lock b/uv.lock index 0b51f55..56d27ab 100644 --- a/uv.lock +++ b/uv.lock @@ -1,6 +1,6 @@ version = 1 revision = 3 -requires-python = ">=3.14" +requires-python = ">=3.10" [[package]] name = "luhn-algorithm"