Repository navigation
Conversation
…der strict pyrefly Replace the type suppressions these two modules needed with real annotations and explicit narrowing helpers, so both can leave the strict-mode exclusion list. - Annotate every test and stub method, using a shared mapping helper instead of casting the untrusted JSON payloads. - Narrow the tool invoke message union with isinstance assertions before touching a concrete variant. - Forward the abstract index processor methods through the base class directly, because the super() form resolves to an unimplemented abstract member.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-26 22:02:36.024163039 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-26 22:02:24.532102606 +0000
@@ -4055,26 +4055,6 @@
--> tests/unit_tests/core/tools/utils/dataset_retriever/test_dataset_multi_retriever_tool.py:418:31
ERROR Argument `_FakeFlaskApp` is not assignable to parameter `flask_app` with type `Flask` in function `core.tools.utils.dataset_retriever.dataset_multi_retriever_tool.DatasetMultiRetrieverTool._retriever` [bad-argument-type]
--> tests/unit_tests/core/tools/utils/dataset_retriever/test_dataset_multi_retriever_tool.py:469:31
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:155:16
-ERROR Argument `Literal['not a dict']` is not assignable to parameter `d` with type `dict[str, Any]` in function `core.tools.utils.message_transformer.safe_json_dict` [bad-argument-type]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:379:32
-ERROR Argument `list[int]` is not assignable to parameter `d` with type `dict[str, Any]` in function `core.tools.utils.message_transformer.safe_json_dict` [bad-argument-type]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:382:32
-ERROR Argument `Literal[42]` is not assignable to parameter `d` with type `dict[str, Any]` in function `core.tools.utils.message_transformer.safe_json_dict` [bad-argument-type]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:385:32
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:424:48
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:461:48
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:507:24
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:530:48
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:551:48
-ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `json_object` [missing-attribute]
- --> tests/unit_tests/core/tools/utils/test_message_transformer.py:608:48
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]
--> tests/unit_tests/core/tools/workflow_as_tool/test_tool.py:78:56
ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `variable_name` [missing-attribute]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46442 +/- ##
==========================================
+ Coverage 90.31% 90.36% +0.04%
==========================================
Files 6495 6512 +17
Lines 408426 409804 +1378
Branches 81921 82040 +119
==========================================
+ Hits 368857 370299 +1442
+ Misses 33163 33109 -54
+ Partials 6406 6396 -10
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:
|
# Conflicts: # api/tests/unit_tests/pyrefly.toml
| @@ -347,7 +376,7 @@ def test_download_image_validates_size_and_empty_content(self, processor: _Forwa | |||
| empty = Mock() | |||
|
Done. The four responses are now real The two remaining Verified: file goes 0 diagnostics under the strict tests project, 23 tests pass, ruff clean. |
There was a problem hiding this comment.
4 inline suggestions at a7a0ac4b2d, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
Use a ParamSpec for the forwarding index processor stub, drop the runtime dict guard in safe_json_dict in favour of a precise Mapping parameter, and read transformed JSON payloads through pydantic models instead of ad hoc isinstance assertions.
There was a problem hiding this comment.
2 inline suggestions at 28c34e1a7b, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
|
The |
…nsformer Resolve the conflict in test_index_processor_base.py by keeping this branch's ParamSpec forwarding overrides and the _image_response helper (real httpx responses always carry a request so raise_for_status cannot silently fail), and dropping the now-unused imports the upstream variant needed.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 3b95dd0f5f, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 3 review threads are still unresolved.
dify-codereview
|
Update on the latest |
…d-message-transformer Take upstream parametrised MIME test, which supersedes the branch copy and covers both None and empty values.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 10aab35e50, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 2 review threads are still unresolved.
dify-codereview
|
|
||
|
|
||
| def safe_json_dict(d: dict[str, Any]): | ||
| def safe_json_dict(d: object) -> dict[object, object]: |
There was a problem hiding this comment.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
The broad type matches the existing runtime contract here. This parameter is the validation boundary: the helper accepts the value and explicitly rejects non-dicts with TypeError. It also preserves non-string keys and passes unsupported nested values through, so a JsonValue return type would promise more than it does. The tests now cover both behaviours.
Why
Two more modules still need blanket exclusion from strict checking: the index
processor base tests and the tool invoke message transformer tests. This brings
both under strict mode, so the exclusion list shrinks and regressions in these
areas get caught by the type checker.
What changed
api/tests/unit_tests/core/rag/index_processor/test_index_processor_base.py(43 → 0)super().method(...)because the inheritedmember is abstract, so it calls
BaseIndexProcessor.method(self, ...)directly. This keeps the original behaviour of asserting that the base
implementation raises.
api/tests/unit_tests/core/tools/utils/test_message_transformer.py(47 → 0)ToolInvokeMessage.messageunion withisinstanceassertionsbefore touching a concrete variant, and additionally narrowed
json_object(which isdict | list) before indexing it.type(self).last_call = ...with a class-level declaration.No suppression comments were added, and none of the pre-existing
typing.castcalls were extended: the two modules now pass strict checking with real
annotations and explicit narrowing.
Verification
exclusion list: 29 errors, all of them the pre-existing
missing-importbaseline, and zero warnings. The 29 are byte-identical to the baseline
set (
file:linecompared one by one).so the fix is what removes them.
pytestfor both modules: 49 passed before and after.ruff checkandruff format --check: clean.