refactor(predict): T-CONTEXTS partial — _predict_batch takes ctx#87
Merged
refactor(predict): T-CONTEXTS partial — _predict_batch takes ctx#87
Conversation
Seventh incremental Parameter Object slice. Tackles the 11-arg offender in PredictGOTermsBatchOperation, the last named target in master plan v3.2 §24 #6. Changes: - protea/core/operations/predict_go_terms.py: - New BatchPredictContext frozen dataclass bundling the 5 required + 5 optional per-call inputs (queries, references, prediction-set handle, payload, optional enrichment maps). - _predict_batch signature collapses 11 args to 1 (ctx). - Single production call site (execute branch) builds the context inline. dataclass field defaults remove the manual None-guard block that used to reset optional dicts on entry. - tests/test_predict_go_terms.py: 6 call sites in TestPredictBatch and TestPredictBatchRerankerFeatures updated to pass BatchPredictContext. Smell budget: 74 -> 73 offenders. params>6: 19 -> 18 (_predict_batch retired). File LOC and execute method LOC tick up by 31 / 2 respectively (dataclass + multi-line ctor); both pre-existing offenders, baseline refreshed via --write-baseline. Local-first 5 verde: ruff, flake8, mypy (predict_go_terms clean; 13 pre-existing test errors on develop unchanged), pytest tests/ (1163 passed, 11 skipped), check_smells.py.
5 tasks
frapercan
added a commit
that referenced
this pull request
May 8, 2026
…#94) ## Acceptance criteria (master plan §24 Fase 1 — T-CONTEXTS partial) Tenth incremental Parameter Object slice. Tackles the 8-arg KNN helper for the aspect-separated path in ``PredictGOTermsBatchOperation``, the largest remaining unnamed params offender in ``predict_go_terms`` after ``_predict_batch`` (#87). Satisfies AC \"ninguna firma productiva >6 args\". ## Changes - `protea/core/operations/predict_go_terms.py`: - New ``AspectSeparatedKnnContext`` frozen dataclass alongside ``BatchPredictContext`` (6 fields: ``valid_accessions``, ``query_embeddings``, ``ref_data_by_aspect``, ``annotation_set_id``, ``prediction_set_id``, ``payload``). - ``_run_aspect_separated_knn`` signature collapses 8 args to 3 (``self``, ``session``, ``ctx``). Body unpacks ctx fields onto locals at entry to keep the ~200-LOC function body diff-free below the signature change. - Single production call site (``execute`` branch) builds the context inline. No tests reference ``_run_aspect_separated_knn`` directly (the path is exercised via the ``execute()`` integration suite). ## Smell budget **params>6: 16 -> 15** (``_run_aspect_separated_knn`` retired). File LOC ticks up 1952 -> 1978 (+26 dataclass) and ``execute`` method 338 -> 340 (+2 multi-line ctor); both pre-existing offenders, baseline refreshed via ``--write-baseline``. ## Test plan - [x] `poetry run ruff check protea scripts` - [x] `poetry run flake8 protea/` - [x] `poetry run mypy protea/core/operations/predict_go_terms.py` (Success: no issues found) - [x] `poetry run pytest tests/ --ignore=tests/test_jobs_pg.py` (1163 passed, 11 skipped) - [x] `poetry run python scripts/check_smells.py`
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.
Acceptance criteria (master plan §24 Fase 1 — T-CONTEXTS partial)
Seventh incremental Parameter Object slice. Tackles the 11-arg offender
_predict_batchinPredictGOTermsBatchOperation— the last named target in master plan v3.2 §24 #6 alongside_knn_transfer_and_label(#80),export_reranker_parquets(#83), and_dump_frozen_dataset(#83).Changes
protea/core/operations/predict_go_terms.py:BatchPredictContextfrozen dataclass bundling the 5 required + 5 optional per-call inputs (queries, references, prediction-set handle, payload, optional enrichment maps)._predict_batchsignature collapses 11 args to 1 (ctx).executebranch) builds the context inline;field(default_factory=dict)removes the manualref_sequences = ref_sequences or {}reset block.tests/test_predict_go_terms.py: 6 call sites inTestPredictBatchandTestPredictBatchRerankerFeaturesretargeted to pass aBatchPredictContextinstance.Smell budget
74 -> 73 offenders. params>6: 19 -> 18 (
_predict_batchretired). File LOC ticks up 1921 -> 1952 (+31 dataclass) andexecutemethod 336 -> 338 (+2 multi-line ctor); both pre-existing offenders, baseline refreshed via--write-baseline.Test plan
poetry run ruff check protea scriptspoetry run flake8 protea/poetry run mypy protea/core/operations/predict_go_terms.py(Success: no issues found)poetry run pytest tests/ --ignore=tests/test_jobs_pg.py(1163 passed, 11 skipped)poetry run python scripts/check_smells.py(73 known, none new)