Skip to content

chore: replace two enums with literals (3/4) - #1286

Draft
selmanozleyen wants to merge 1 commit into
feat/stain-reference-methodsfrom
feat/enum-to-literal
Draft

chore: replace two enums with literals (3/4)#1286
selmanozleyen wants to merge 1 commit into
feat/stain-reference-methodsfrom
feat/enum-to-literal

Conversation

@selmanozleyen

Copy link
Copy Markdown
Member

Continuation of #1279. Because we don't want to expose different classes for this anymore

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.
@selmanozleyen selmanozleyen changed the title replace two enums with literals chore: replace two enums with literals Sep 3, 2026
@selmanozleyen selmanozleyen changed the title chore: replace two enums with literals chore: replace two enums with literals (3/4) Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.14286% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.23%. Comparing base (1ba759b) to head (519c1f3).

Files with missing lines Patch % Lines
src/squidpy/experimental/im/_detect_tissue.py 75.00% 1 Missing and 2 partials ⚠️
src/squidpy/experimental/im/_qc_image.py 92.30% 1 Missing ⚠️
src/squidpy/experimental/pl/_qc_image.py 0.00% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
src/squidpy/experimental/im/_qc_metrics.py 100.00% <100.00%> (ø)
src/squidpy/experimental/im/_qc_image.py 85.39% <92.30%> (+2.90%) ⬆️
src/squidpy/experimental/pl/_qc_image.py 60.91% <0.00%> (+0.69%) ⬆️
src/squidpy/experimental/im/_detect_tissue.py 69.42% <75.00%> (-0.42%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant