Skip to content

Commit

Permalink
Fix type-soup when calculating checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Apr 8, 2024
1 parent bb2175a commit 4c0c3a4
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions barcode/ean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

__docformat__ = "restructuredtext en"

from functools import reduce

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

def sum_(x, y):
return int(x) + int(y)

ean_without_checksum = self.ean[: self.digits]

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

def build(self):
Expand Down Expand Up @@ -216,13 +212,10 @@ def calculate_checksum(self) -> int:
:returns: The checksum for ``self.ean``.
"""

def sum_(x, y):
return int(x) + int(y)

ean_without_checksum = self.ean[: self.digits]

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


Expand Down

0 comments on commit 4c0c3a4

Please sign in to comment.