Skip to content

Commit 0bd796a

Browse files
canklotWhyNotHugo
authored andcommitted
Fix issue #171 calculating checksum before any controls
Moved `super().__init__` before calling `_calculate_checksum()` to check if the string contains any letters to prevent value errors that can happen when calculating checksum. I tested the new version with the input `0132354187` and the produced barcode before and after the commit is the same as `9780132352`.
1 parent 7dd1609 commit 0bd796a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

barcode/isxn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class InternationalStandardBookNumber10(InternationalStandardBookNumber13):
6969
def __init__(self, isbn, writer=None):
7070
isbn = isbn.replace("-", "")
7171
isbn = isbn[: self.digits]
72+
super().__init__("978" + isbn, writer)
7273
self.isbn10 = isbn
7374
self.isbn10 = f"{isbn}{self._calculate_checksum()}"
74-
super().__init__("978" + isbn, writer)
75+
7576

7677
def _calculate_checksum(self):
7778
tmp = sum(x * int(y) for x, y in enumerate(self.isbn10[:9], start=1)) % 11

0 commit comments

Comments
 (0)