Summary
In __format__, each named group is fetched from the regex match twice — once to test truthiness, once to use the value:
fill = match.group("fill") if match.group("fill") else fill
align = match.group("align") if match.group("align") else align
width = int(match.group("width")) if match.group("width") else width
grouping = match.group("grouping") if match.group("grouping") else grouping
unit = match.group("unit").upper() if match.group("unit") else unit
Location
src/fsize/__init__.py, lines 179–185.
Issues
- Each group lookup is performed twice (5 lines × 2 calls = 10 total vs. 5 needed).
- If a group name is ever misspelled, both the condition and the value evaluate to
None/falsy, and the default silently applies — no IndexError until a separate code path.
Fix
Use or to fetch once:
fill = match.group("fill") or fill
align = match.group("align") or align
width = int(match.group("width")) if match.group("width") else width
grouping = match.group("grouping") or grouping
unit = (match.group("unit") or unit).upper()
(width still needs the conditional form because int(None) raises, but all others work cleanly with or.)
Summary
In
__format__, each named group is fetched from the regex match twice — once to test truthiness, once to use the value:Location
src/fsize/__init__.py, lines 179–185.Issues
None/falsy, and the default silently applies — noIndexErroruntil a separate code path.Fix
Use
orto fetch once:(
widthstill needs the conditional form becauseint(None)raises, but all others work cleanly withor.)