Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions luhn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

from __future__ import annotations

from typing import Union

NumberLike = Union[str, int]
NumberLike = str | int
REMOVE_CHARS = " -./\\,"
DIGIT_CLEANUP_TABLE = str.maketrans("", "", REMOVE_CHARS)


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)

Expand Down
Loading