Skip to content

Wire the generics the docs list to their methods, drop the sixteen with nothing behind them - #148

Merged
shanikawm merged 1 commit into
mainfrom
fix/generics-no-stubs-142
Oct 7, 2026
Merged

shanikawm merged 1 commit into
mainfrom
fix/generics-no-stubs-142

Conversation

@shanikawm

Copy link
Copy Markdown
Contributor

Fixes #142.

truecell.generics declared 72 functions, and 39 had only the NotImplementedError fallback registered, so each raised for every object. skills/truecell/reference/api-map.md listed many of them as the way to do things, and docs/api/generics.md says each generic is "the same code path" as the object's own method. The issue offered two fixes, wiring them up or removing them. The rule I applied per name is whether something already exists behind it.

Wired: 23 generics now delegate

assay_names, calc_n, cast_assay, reorder_ident, set_ident, tool, set_tool, version, set_layer_data, set_assay_data, set_loadings, set_default_assay, set_default_layer, set_variable_features, set_key, misc, set_misc, the spatial as_centroids, crop, overlay, default_boundary and get_molecules, and command.

They hand their arguments through untouched, so a method's signature has no second copy to drift, which is how this happened. Where the target is a settable property (default_assay, default_layer, variable_features, key), the generic goes through the property, so its validation applies. VisiumV2 is an FOV, so it dispatches the same.

command is the one with new logic, since the log is a list of entries and R's is a named list. I read Command.Seurat from the installed SeuratObject rather than rely on memory, and my memory was wrong in two places: R errors on an unknown command (I had it warning), and value reads only params, not the name or time stamp. Both are mirrored, and so is "a command run twice appears once, holding its latest run".

Removed: 16 generics

Nothing could call any of them successfully, so no working code changes.

  • create_truecell_object, create_assay_object, create_fov, create_centroids, create_segmentation. The top-level functions of the same names are the constructors. I tried wiring these, but a singledispatch needs a positional first argument and the documented call style is create_truecell_object(counts=...), so the wired version would have been worse than the real one.
  • as_segmentation, as_seurat, assay_class, default_dim_reduc, default_fov, hvf_info, keys, list_to_s4, s4_to_list. Nothing in the port is behind them. HVFInfo()'s table is the per-feature columns of assay.meta_data, which an earlier release made match R's names.
  • check_matrix, match_cells. Internal helpers exist under those names, but they do something other than R's CheckMatrix and MatchCells (the second is documented as "like R match()"), so wiring them would put a different meaning under an R name.

There is precedent for removing rather than stubbing: test_stitch_matrix_is_removed. This is the one judgement call in the PR. If you would rather have any of the 16 as real features, hvf_info, keys, default_fov and default_dim_reduc are the plausible ones, and each is a small feature of its own rather than wiring.

Docs and guards

  • The api-map list loses the 11 removed names it named, and says what R's constructors and HVFInfo() map to instead. docs/api/index.md and tests/test_docs.py count the module-only generics, which goes from 65 to 54.
  • tests/test_generics.py (36 tests): fails on a generic with no implementation, and on a mismatch in either direction between the module and the api-map's list. The issue suggested the first; the second is what lets the prose list stop drifting. The rest compare each delegate with the method it claims to be.

Verification

  • Mutation-tested, eight mutants, each failing its own test: a stub re-declared (three tests), tool and crop mis-wired, command keeping the first run instead of the latest, set_variable_features ignoring assay, set_misc unable to replace the dict, the fallback no longer marking itself, and command reading slots as well as params.
  • Full suite locally: 1776 passed, 30 skipped, including the mkdocs --strict build. ruff is unchanged on the files touched (generics.py 1, test_docs.py 2), and mypy shows its 4 baseline errors in 2 files. It caught one thing on the way, a loop variable reused across two tuples of different types, now fixed.
  • No file in the repo references a removed generic as generics.<name>, including notebooks.

No release is needed for this change on its own. The CHANGELOG has a Fixed and a Removed entry under [Unreleased].

🤖 Generated with Claude Code

…th nothing behind them (#142)

truecell.generics declared 72 functions and 39 had only the NotImplementedError
fallback, so each raised for every object. The api-map listed many as the way
to do things, and docs/api/generics.md says each is the same code path as the
object's own method.

Twenty-three now delegate to the method, property or log that already existed,
with arguments handed through untouched so a signature has no second copy to
drift. command reads the command log as R's Command() does, checked against
SeuratObject's source: it errors on an unknown command, reads only params for a
value, and shows a command run twice once, holding its latest run.

Sixteen are removed. The five create_* constructors are the top-level functions,
which take their input by keyword where a dispatcher on the first positional
argument cannot. Nine have no counterpart in the port. check_matrix and
match_cells had internal helpers behind them that do something other than R's
CheckMatrix and MatchCells. Nothing could call any of them, so no working code
changes. The api-map list and the 65 module-only generics that docs/api/index.md
and test_docs.py count (now 54) follow.

tests/test_generics.py walks the module and fails on a generic with no
implementation, and on a mismatch in either direction with the api-map's list.
Eight mutants, among them a stub re-declared, mis-wired delegates and the
command log's semantics, each fail their own test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@shanikawm
shanikawm merged commit c000f9d into main Oct 7, 2026
8 checks passed
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.

39 of 72 functions in truecell.generics have no implementation and raise NotImplementedError for every type

1 participant