Skip to content

Fix checkdigit calculation for ISBN10 - #292

Merged
yezz123 merged 1 commit into
pydantic:mainfrom
eumiro:fix-isbn10-checkdigit
Mar 3, 2025
Merged

yezz123 merged 1 commit into
pydantic:mainfrom
eumiro:fix-isbn10-checkdigit

Conversation

@eumiro

@eumiro eumiro commented Mar 2, 2025

Copy link
Copy Markdown
Contributor

The code calculating checkdigit for ISBN10 runs a loop for numbers between 1 and 10 included. There are two issues:

  1. it ignores the possibility of getting the checkdigit of 0 and then raises an UnboundLocalError because the variable valid_check_digit is never set
  2. it actually does not have to run a loop to calculate this variable, therefore a minor performance optimization is possible

This PR includes an added test with a valid ISBN10 ending with a 0 that failed earlier but passes now.

@yezz123 yezz123 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@yezz123
yezz123 merged commit a31555e into pydantic:main Mar 3, 2025
@eumiro
eumiro deleted the fix-isbn10-checkdigit branch March 3, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants