WhyNotHugo / python-barcode

㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.
http://python-barcode.rtfd.io/
MIT License
572 stars 123 forks source link

Fix issue #171 calculating checksum before any controls #172

Closed canklot closed 2 years ago

canklot commented 2 years ago

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.

codecov[bot] commented 2 years ago

Codecov Report

Base: 80.58% // Head: 80.58% // No change to project coverage :thumbsup:

Coverage data is based on head (f25d71b) compared to base (7dd1609). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #172 +/- ## ======================================= Coverage 80.58% 80.58% ======================================= Files 17 17 Lines 886 886 ======================================= Hits 714 714 Misses 172 172 ``` | [Impacted Files](https://codecov.io/gh/WhyNotHugo/python-barcode/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+Osvaldo+Barrera) | Coverage Δ | | |---|---|---| | [barcode/isxn.py](https://codecov.io/gh/WhyNotHugo/python-barcode/pull/172/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+Osvaldo+Barrera#diff-YmFyY29kZS9pc3huLnB5) | `86.53% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+Osvaldo+Barrera). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+Osvaldo+Barrera)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

WhyNotHugo commented 2 years ago

Is the error because the checksum contains letters? Never mind, the checksum can't have letters either.

WhyNotHugo commented 2 years ago

This merely changes the error raised to be the correct one, if I understand correctly, right?

canklot commented 2 years ago

This merely changes the error raised to be the correct one, if I understand correctly, right?

Yes instead of getting invalid literal for int() with base 10: now it returns IllegalCharacterError('EAN code can only contain numbers.')

WhyNotHugo commented 2 years ago

Makes sense, thanks