Repository navigation
refactor(api): enable strict typing for schema resolver tests - #44050
Merged
asukaminato0721 merged 1 commit intoOct 14, 2026
Merged
asukaminato0721 merged 1 commit into
asukaminato0721 merged 1 commit into
Conversation
Bring the core/schemas unit tests under Pyrefly strict mode. resolve_dify_schema_refs and SchemaResolver.resolve return SchemaType, a union of dict, list and scalars; the tests indexed the result directly, which accounted for 129 of the 201 diagnostics. Assert the resolved schema is a dict before reading keys, build the deeply nested performance schemas with a typed helper instead of mutating dicts through untyped indexing, type the thread results and the recursive deep_schema, and remove the three files from the Pyrefly exclusions.
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-10-14 05:17:01.787421788 +0000
+++ /tmp/pyrefly_pr.txt 2026-10-14 05:16:53.387397977 +0000
@@ -3822,286 +3822,6 @@
--> tests/unit_tests/core/repositories/test_sqlalchemy_workflow_execution_repository.py:301:33
ERROR `None` is not assignable to attribute `_creator_user_role` with type `CreatorUserRole` [bad-assignment]
--> tests/unit_tests/core/repositories/test_sqlalchemy_workflow_execution_repository.py:306:35
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:42:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:43:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:44:31
-ERROR `not in` is not supported between `Literal['$id']` and `bool` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:48:16
-ERROR `not in` is not supported between `Literal['$id']` and `float` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:48:16
-ERROR `not in` is not supported between `Literal['$id']` and `int` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:48:16
-ERROR `not in` is not supported between `Literal['$id']` and `None` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:48:16
-ERROR `not in` is not supported between `Literal['$schema']` and `bool` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:49:16
-ERROR `not in` is not supported between `Literal['$schema']` and `float` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:49:16
-ERROR `not in` is not supported between `Literal['$schema']` and `int` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:49:16
-ERROR `not in` is not supported between `Literal['$schema']` and `None` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:49:16
-ERROR `not in` is not supported between `Literal['version']` and `bool` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:50:16
-ERROR `not in` is not supported between `Literal['version']` and `float` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:50:16
-ERROR `not in` is not supported between `Literal['version']` and `int` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:50:16
-ERROR `not in` is not supported between `Literal['version']` and `None` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:50:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:65:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:66:30
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:91:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:92:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:95:24
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:112:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:115:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:116:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:133:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:134:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:135:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:136:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:150:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:150:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:150:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:150:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:150:16
-ERROR `in` is not supported between `Literal['$circular_ref']` and `bool` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:170:16
-ERROR `in` is not supported between `Literal['$circular_ref']` and `float` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:170:16
-ERROR `in` is not supported between `Literal['$circular_ref']` and `int` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:170:16
-ERROR `in` is not supported between `Literal['$circular_ref']` and `None` [not-iterable]
- --> tests/unit_tests/core/schemas/test_resolver.py:170:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:182:16
-ERROR Argument `Exception` is not assignable to parameter `object` with type `bool | dict[str, Any] | float | int | list[Any] | str | None` in function `list.append` [bad-argument-type]
- --> tests/unit_tests/core/schemas/test_resolver.py:233:32
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:273:16
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR Cannot index into `list[Any]` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:274:27
-ERROR Cannot set item in `str` [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:593:13
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:594:23
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:667:13
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:667:13
-ERROR Cannot set item in `str` [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:667:13
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/unit_tests/core/schemas/test_resolver.py:667:51
-ERROR `dict[@_, @_]` is not assignable to dict value type `str` [bad-assignment]
- --> tests/unit_tests/core/schemas/test_resolver.py:667:84
-ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:668:23
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:668:23
-ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/schemas/test_resolver.py:668:23
ERROR Argument `Literal[core.entities.provider_entities.ProviderQuotaType.TRIAL]` is not assignable to parameter `quota_type` with type `models.enums.ProviderQuotaType | SQLCoreOperations[models.enums.ProviderQuotaType | None] | None` in function `models.provider.Provider.__init__` [bad-argument-type]
--> tests/unit_tests/core/test_provider_manager.py:114:20
ERROR Argument `Literal['llm']` is not assignable to parameter `model_type` with type `ModelType | SQLCoreOperations[ModelType]` in function `models.provider.ProviderModelSetting.__init__` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44050 +/- ##
==========================================
- Coverage 88.92% 88.92% -0.01%
==========================================
Files 5332 5332
Lines 329404 329404
Branches 65910 65910
==========================================
- Hits 292923 292920 -3
- Misses 31282 31286 +4
+ Partials 5199 5198 -1
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:
|
asukaminato0721
enabled auto-merge
October 14, 2026 10:01
asukaminato0721
approved these changes
Oct 14, 2026
This was referenced Oct 15, 2026
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.
Summary
Part of #24645, following #44040.
The three
core/schemastest modules (test_registry.py,test_resolver.py,test_schema_manager.py) were excluded from strict Pyrefly checks and produced 201 diagnostics.129 of them came from one pattern in
test_resolver.py:resolve_dify_schema_refsandSchemaResolver.resolvereturnSchemaType, a union ofdict,list,str,int,float,boolandNone.resolved["properties"]["name"]["type"]).The rest were:
No production code changes.
What changed
test_resolver.pyisinstance(resolved, dict)right after resolving, which is what each of them expects from resolving a dict schema. The list case already assertedisinstance(resolved, list).current["properties"][...]and mutating it, which cannot be typed. A small_nested_schema(depth)helper now builds the same structure from the inside out.deep_schema, which is rebound to a dict containing itself, is annotateddict[str, object].list[object].test_registry.py/test_schema_manager.py. Type the empty containers and the patcheddefault_registrymock.-> None, and remove them from the unit-test Pyrefly exclusions.test_resolver.pykeeps itstests/unit_tests/.ruff.tomlentry (ARG005,T201) for now: that line sits next to lines open PR #43214 edits, so removing it here would add a conflict there.Verification
pyrefly check --config=tests/unit_tests/pyrefly.toml --use-ignore-files=false --disable-project-excludes-heuristics=trueon the three files (fromapi/): 201 diagnostics before the change, zero after.pyrefly check --config=tests/unit_tests/pyrefly.tomlover the whole unit-test project: passed.ruff format --checkandruff check, on the files and on the wholeapi/treelint-imports: 68 contracts keptscripts/check_no_new_getattr.py,check_no_new_controller_sqlalchemy.py,check_no_new_session_mock.pyandcheck_no_spec_mock.pypyteston the three files with-von Python 3.13: 46 passed, the same 46 test IDs as before the change.Screenshots
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods (backend only: ran the underlying ruff, import-linter, guard-script and Pyrefly commands listed above)From Claude Code