python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

Cleanup Barcode.build()

Open maresb opened this issue 1 year ago • 1 comments

This is a follow-up to #228. I'm trying to not break backwards-compatibility for now, but just to make the code more understandable.

maresb avatar Apr 28 '24 19:04 maresb

There's so much to do here. I'm grinding away, fixing stuff that catches my eye. If you let me know what you like and don't like, I can eventually try and rebase out the good parts.

maresb avatar Apr 29 '24 08:04 maresb

Sorry for the slow reply, these were a lot of changes and needed serious attention.

Ya, honestly I felt bad for dumping this mess on you. Thanks so much for sifting through it!!! This looks quick, let me see if I can crank this out now...

maresb avatar Jul 08 '24 17:07 maresb

I got pytest running. Now I'm looking into:

>       raise RuntimeError(
            f"Character {char} could not be converted in charset {self._charset}."
        )
E       RuntimeError: Character 9 could not be converted in charset C.

maresb avatar Jul 08 '24 18:07 maresb

Ok, cool, I introduced this exception in 5ff0cd7 :joy:

maresb avatar Jul 08 '24 18:07 maresb

@WhyNotHugo, could you please re-review? I think I've addressed your concerns. Also, I tried to make the individual commits very simple.

~One potentially confusing commit is "Parametrize test_generating_barcodes". I preserved the HTML by creating a module-scoped fixture that collects the individual HTML image elements. This way the test cases can pass or fail independently.~ (Split out into #233)

The other commit that requires some thought is "Cleanup Barcode.build()". The logic here is that only one invocation of self._convert can possibly encode a digit from charset C which results in returning None. Thus I split it out this case into a separate function _convert_or_buffer. While it's more lines-of-code, I think it's easier to understand being more type-friendly and less like a mysterious finite-state automaton.

maresb avatar Jul 08 '24 22:07 maresb

If it's too much then let me know and I'll split it into multiple PRs.

maresb avatar Jul 08 '24 22:07 maresb

I've triggered a rebase after merging https://github.com/WhyNotHugo/python-barcode/pull/233.

Feel free to rebase locally and force-push if you had any pending changes.

WhyNotHugo avatar Jul 09 '24 14:07 WhyNotHugo

Thanks @WhyNotHugo!!! I agree with the rebase.

I split off the non-minimal changes into #234, so the only unreviewed commits are the last four, directly addressing your feedback above, and I'd expect those four to be super-quick to review.

maresb avatar Jul 09 '24 14:07 maresb

@WhyNotHugo, there is no urgency whatsoever on this, but it seems like you reviewed all but the last four small commits, so perhaps this is simple to merge.

maresb avatar Jul 20 '24 13:07 maresb

I think this is okay to merge. There are commits that make changes and later commits that revert them. Do you want to rebase this? Otherwise I'll just squash them into a single commit.

WhyNotHugo avatar Jul 29 '24 12:07 WhyNotHugo

Let's squash. Thanks @WhyNotHugo!!!

maresb avatar Jul 29 '24 12:07 maresb

Thanks!

WhyNotHugo avatar Jul 30 '24 08:07 WhyNotHugo