jw-python/src
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jan Lindemann b192207bbd
Options.get(): Fix inverted by_index check
The by_index branch of Options.get() raises KeyError for every integer
index, because the first isinstance guard is inverted: it fires for exactly
the keys the branch is supposed to handle, so the range check and the
lookup in the list of parsed keys below it are dead code. A non-integer key
with by_index set slips past the guard and falls through to the regular key
lookup instead. A previous make-check fallout commit flipped the original
type(key) != int test into a positive isinstance test, and a later mypy fix
then added redundant isinstance guards to the unreachable branches,
cementing the broken flow.

Invert the guard back to not isinstance(key, int), so that a non-integer
key raises KeyError, an in-range integer index returns the key stored at
that position in the option string, and an out-of-range index returns the
default or raises KeyError. Drop the redundant isinstance guards from the
now-reachable branches.

TODO: The bug actually made "make -C test/parse_opts run" fail, but since
jw-python's nightly CI doesn't run that, this has gone unnoticed. The test
now passes, but should be replaced with a better test (executed by "make
test", and pytest-based).

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-18 09:44:26 +02:00
..
python Options.get(): Fix inverted by_index check 2026-09-18 09:44:26 +02:00
Makefile jwutils: Move to jwutils -> jw.util 2026-06-11 23:10:25 +00:00