Repository navigation
Wire the generics the docs list to their methods, drop the sixteen with nothing behind them - #148
Merged
Merged
Conversation
…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>
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.
Fixes #142.
truecell.genericsdeclared 72 functions, and 39 had only theNotImplementedErrorfallback registered, so each raised for every object.skills/truecell/reference/api-map.mdlisted many of them as the way to do things, anddocs/api/generics.mdsays 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 spatialas_centroids,crop,overlay,default_boundaryandget_molecules, andcommand.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.VisiumV2is anFOV, so it dispatches the same.commandis the one with new logic, since the log is a list of entries and R's is a named list. I readCommand.Seuratfrom 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), andvaluereads onlyparams, 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 asingledispatchneeds a positional first argument and the documented call style iscreate_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 ofassay.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'sCheckMatrixandMatchCells(the second is documented as "like Rmatch()"), 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_fovanddefault_dim_reducare the plausible ones, and each is a small feature of its own rather than wiring.Docs and guards
HVFInfo()map to instead.docs/api/index.mdandtests/test_docs.pycount 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
toolandcropmis-wired,commandkeeping the first run instead of the latest,set_variable_featuresignoringassay,set_miscunable to replace the dict, the fallback no longer marking itself, andcommandreading slots as well as params.mkdocs --strictbuild. ruff is unchanged on the files touched (generics.py1,test_docs.py2), 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.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