Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 7 additions & 8 deletions domdf_python_tools/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ def alpha_sort(

alphabet_ = list(alphabet)

try:
return sorted(iterable, key=lambda attr: [alphabet_.index(letter) for letter in attr], reverse=reverse)
except ValueError as e:
m = re.match(r"'(.*)' is not in list", str(e))
if m:
raise ValueError(f"The character {m.group(1)!r} was not found in the alphabet.") from None
else: # pragma: no cover
raise e
def _alphabet_index(letter: str) -> int:
try:
return alphabet_.index(letter)
except ValueError:
raise ValueError(f"The character {letter!r} was not found in the alphabet.") from None

return sorted(iterable, key=lambda attr: [_alphabet_index(letter) for letter in attr], reverse=reverse)


class Font(Dict[str, str]):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_printr(obj, expects, capsys):
assert re.match(expects, stdout[0])


if sys.version_info >= (3, 13):
if sys.version_info[:2] == (3, 13):
pure_posix_path_expected = "<class 'pathlib._local.PurePosixPath'>"
else:
pure_posix_path_expected = "<class 'pathlib.PurePosixPath'>"
Expand Down