Skip to content

Commit 4c0c3a4

Browse files
committed
Fix type-soup when calculating checksums
1 parent bb2175a commit 4c0c3a4

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

barcode/ean.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
__docformat__ = "restructuredtext en"
88

9-
from functools import reduce
109

1110
from barcode.base import Barcode
1211
from barcode.charsets import ean as _ean
@@ -83,13 +82,10 @@ def calculate_checksum(self) -> int:
8382
:returns: The checksum for ``self.ean``.
8483
"""
8584

86-
def sum_(x, y):
87-
return int(x) + int(y)
88-
8985
ean_without_checksum = self.ean[: self.digits]
9086

91-
evensum = reduce(sum_, ean_without_checksum[-2::-2])
92-
oddsum = reduce(sum_, ean_without_checksum[-1::-2])
87+
evensum = sum(int(x) for x in ean_without_checksum[-2::-2])
88+
oddsum = sum(int(x) for x in ean_without_checksum[-1::-2])
9389
return (10 - ((evensum + oddsum * 3) % 10)) % 10
9490

9591
def build(self):
@@ -216,13 +212,10 @@ def calculate_checksum(self) -> int:
216212
:returns: The checksum for ``self.ean``.
217213
"""
218214

219-
def sum_(x, y):
220-
return int(x) + int(y)
221-
222215
ean_without_checksum = self.ean[: self.digits]
223216

224-
evensum = reduce(sum_, ean_without_checksum[::2])
225-
oddsum = reduce(sum_, ean_without_checksum[1::2])
217+
evensum = sum(int(x) for x in ean_without_checksum[::2])
218+
oddsum = sum(int(x) for x in ean_without_checksum[1::2])
226219
return (10 - (((evensum * 3) + oddsum) % 10)) % 10
227220

228221

0 commit comments

Comments
 (0)