Releases: mikeckennedy/python-switch
v0.1.3
[0.1.3] - 2026-06-11
Fixed
- An exception raised inside the
withblock now always aborts the switch,
even when the exception object is falsy.__exit__guarded its re-raise with
if exc_val:, a truthiness test that invokes the exception's__bool__/__len__.
An exception whose__bool__returnedFalseslipped past the guard, so the
matched case action ran before the exception propagated. The guard now tests
exc_val is not None, restoring the documented "no case actions run on
exception" guarantee for every exception type.
(#15)
v0.1.2
Two long-standing bug fixes, a brand-new documentation site, full typing support, and modernized packaging. Quite a bit packed into a patch release!
Bug fixes 🐛
closed_range() overshot stop when step > 1. closed_range(1, 6, 2) produced 1, 3, 5, 7 — quietly matching values outside the stated range in a switch block. It now correctly yields 1, 3, 5, never passing stop, while still including stop when the step lands on it exactly: closed_range(1, 7, 2) → 1, 3, 5, 7. A step less than 1 now raises a clear ValueError instead of a raw range error (step=0) or a silently empty range (negative step). #14
switch.result could mistake a real result for "no result computed". The internal no-result sentinel was compared with ==, so a matched case returning an object with permissive equality — numpy arrays are the classic case — raised No result has been computed even though one was. The sentinel is now compared by identity. #14
Both bugs dated back to 2017, and both fixes ship with regression tests (there's a full retrospective on the issue if you enjoy that kind of thing). If your code somehow depended on closed_range overshooting, consider this your heads-up — it doesn't anymore.
New documentation site 📚
switchlang now has proper documentation — a getting-started guide plus a complete API reference generated from the new docstrings:
https://mkennedy.codes/docs/python-switch/
Fully typed
The package now ships a py.typed marker with complete type annotations across the public API, so your editor and type checker finally know what s.result is. #13
Packaging and quality
- Modern packaging:
setup.pyis gone, replaced bypyproject.toml+ hatchling, with support declared for Python 3.9 through 3.15. - Docstrings across the entire public API — they're what power the docs site.
- The test suite grew from 19 to 29 tests, including the first tests to exercise a non-default
step, exception propagation, and the documented edge cases. switchlang now sits at 100% line coverage. - ruff lint and format configuration.
Full changelog: v0.1.1...v0.1.2
v0.1.1
Refactor codebase for consistent double‑quoted strings and add type hints
This update replaces single‑quoted literals with double quotes throughout the repository,
standardizes string formatting in setup.py, __init__.py, and test files, and introduces
comprehensive type annotations to improve readability and static analysis support. The changes also
clean up import statements, adjust exception messages for clarity, and ensure the package metadata
uses consistent quoting conventions. 🚀
Solves potential type warning on s.result.