chore: replace two enums with literals (3/4) - #1286
Draft
selmanozleyen wants to merge 1 commit into
Draft
Conversation
Both were closed vocabularies of strings that callers write as strings, and neither earned the class it was declared as. `DetectTissueMethod` used `enum.auto()`, so its members carried no value anyone read; every use was an equality test, and a string argument was coerced through `DetectTissueMethod[method.upper()]` before any of them ran. It was never exported either, while its own docstring told callers to pass `DetectTissueMethod.OTSU` -- advice they could not follow. The `.upper()` in that coercion is why `method` is lowered before the new membership check: `"OTSU"` was accepted before and still is. `QCMetric` was a `StrEnum`, so its members already were their own strings and worked as registry keys unchanged. Its validation, though, was `isinstance(m, QCMetric)`, which is False for the plain string the member compares equal to: `qc_image(metrics="tenengrad")` raised while the docs advertised a `StrEnum`. Both now validate against `get_args`, which accepts what callers actually write. Two behaviour changes worth naming. An unknown metric now raises `ValueError` rather than `TypeError` -- it is a bad value, not a bad type, and the old class was chosen to complain about enum membership. And `QCMetric` leaves the module namespace entirely, not just `__all__`: a page rendering as nothing but `alias of Literal[...]` documents an argument rather than a type callers hold, and the names it listed now sit on the parameter that takes them, in both `im.qc_image` and its `pl` counterpart. `InputKind` stays an enum. It is internal and never crosses the public boundary.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/stain-reference-methods #1286 +/- ##
================================================================
+ Coverage 79.21% 79.23% +0.01%
================================================================
Files 64 64
Lines 9362 9342 -20
Branches 1527 1527
================================================================
- Hits 7416 7402 -14
+ Misses 1396 1391 -5
+ Partials 550 549 -1
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of #1279. Because we don't want to expose different classes for this anymore