Repository navigation
test(api): enable strict typing for jieba keyword table handler tests - #45320
Conversation
Annotate the test declarations and the fake jieba module attributes so that tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py passes strict pyrefly, then drop its entry from the unit-test exclusion list. No assertion, fixture or test behavior changes; the seven missing-attribute diagnostics come from assigning attributes on a plain types.ModuleType used to impersonate jieba.analyse. Verified with pyrefly 1.4.0: 19 diagnostics before, 0 after; the eight tests in the module pass; ruff check and ruff format pass. Contributes to langgenius#24645
Pyrefly Type Coverage
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-04 07:10:21.954836148 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-04 07:10:10.482801959 +0000
@@ -4338,20 +4338,6 @@
--> tests/unit_tests/core/rag/data_post_processor/test_data_post_processor.py:29:29
ERROR Argument `dict[str, str]` is not assignable to parameter `reranking_model` with type `RerankingModelDict | None` in function `core.rag.data_post_processor.data_post_processor.DataPostProcessor._get_rerank_model_instance` [bad-argument-type]
--> tests/unit_tests/core/rag/data_post_processor/test_data_post_processor.py:192:33
-ERROR Object of class `ModuleType` has no attribute `analyse` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:32:5
-ERROR Object of class `ModuleType` has no attribute `default_tfidf` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:46:5
-ERROR Object of class `ModuleType` has no attribute `default_tfidf` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:58:5
-ERROR Object of class `ModuleType` has no attribute `TFIDF` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:63:5
-ERROR Object of class `ModuleType` has no attribute `default_tfidf` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:74:5
-ERROR Object of class `ModuleType` has no attribute `TFIDF` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:81:5
-ERROR Object of class `ModuleType` has no attribute `default_tfidf` [missing-attribute]
- --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:92:5
ERROR Argument `str` is not assignable to parameter `doc_form` with type `IndexStructureType | SQLCoreOperations[IndexStructureType]` in function `models.dataset.Document.__init__` [bad-argument-type]
--> tests/unit_tests/core/rag/datasource/test_retrieval_service.py:148:18
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45320 +/- ##
==========================================
- Coverage 89.84% 89.84% -0.01%
==========================================
Files 6242 6242
Lines 391154 391154
Branches 79217 79217
==========================================
- Hits 351445 351432 -13
- Misses 33607 33618 +11
- Partials 6102 6104 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The reviewer asked to replace the fake TFIDF double with a real class. The tests now subclass jieba.analyse.TFIDF, so the handler exercises the production IDF table and the stop_words attribute it writes, and only the tag list is chosen by the test. The fake module objects keep the real attributes the analyse package exposes, and the loader branches are covered with the real TFIDF class. pyrefly strict check: 0 diagnostics. pytest: 6 passed. ruff check and ruff format pass.
|
@asukaminato0721 I addressed the two things you asked for, in 20a2767:
On the new head: strict pyrefly is 0 diagnostics for this file, the 6 tests pass, and ruff check / ruff format are clean. @GYJ99 thanks for flagging the overlap with #45347 on that other PR — agreed this should land as one change, and #45320 already uses the real Also noting for maintainers: every workflow on 20a2767 is |
ruff's isort rule (I001) groups third-party and first-party imports; the `jieba` import sat above the `core` imports and the check failed on the changed file. Move it into the third-party block so `ruff check` passes with api/.ruff.toml. No behavior change.
|
Friendly follow-up on review: the requested change is in and the branch is now clean. Addressed: Formatting: One note on the Pyrefly report, in case it is read as a regression: Full CI still shows Could you take another look when you have a moment? Thanks. |
Summary
Bring
api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.pyunder strict Pyrefly checking and remove its entry fromapi/tests/unit_tests/pyrefly.toml, continuing #24645 (same pattern as #43883, #43875 and #43798).The module was still excluded from strict checking. Strict Pyrefly (1.4.0) reports 19 diagnostics on it, all fixed here:
unannotated-return-> Noneon the eight tests,_DummyTFIDF.__init__and_install_fake_jieba_modulesimplicit-any-parametermonkeypatch: pytest.MonkeyPatch,**kwargs: objectmissing-attribute# pyrefly: ignore[missing-attribute]The last group is by design: the tests install a fake
jieba.analysewithtypes.ModuleType, then supplydefault_tfidf,TFIDFandanalysefor the handler to discover. AModuleTypedeclares none of those, so the assignment is correct at runtime and the suppression states why.typing.Anyis not used, per the banned-API rule.No assertion, fixture, import list (apart from the dropped
Any) or test behavior changes.What changed
api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py: annotations and the seven scoped suppressions above.api/tests/unit_tests/pyrefly.toml: remove the single exclusion line.Validation
pyrefly check --config=tests/unit_tests/pyrefly.toml --use-ignore-files=false --disable-project-excludes-heuristics=true tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py: 19 diagnostics before, 0 after (pyrefly 1.4.0).ruff checkandruff format --checkpass on the changed file.Contributes to #24645